on 09-16-2008 5:09 AM
Hi everyone,
I'm trying to do a bitwise (AND) operation as part of a report filter and can't seem to find the right way to do it. I must be missing something simple.
For example, how do you do this?
Field1 And 4 = 4
Thanks,
Rod
Thanks for the responses guys, however my issue remains. Perhaps I wasn't clear enough.
I'm trying to do a bitwise comparison, not a logical one.
I have an integer field that stores a composite value and I'm trying to filter a report based on one of the values.
For example if I only want to show records that contain the 4th bit.
The value of the field is 10.
It contains the "bits" of 2 and 8
If I only want values that contain 4, then this record would not be included. Values like 4, 5, 6, 7 would.
In SQL you use the "&" character to do bitwise operations.
In Visual Basic you use something like this.
If (Field1 And 4) = 4 Then Print "The value contains 4"
Hope this explains it a bit better. CR doesn't seem to support this without writing some drawn-out formula to manually calculate the bits for each number ;-(
Thanks,
Rod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rod,
Have you received an answer to this? I am a new member with minimal knowledge of CR and I need to do something similar. My web search turned up virtually nothing except for your query, so I'm really hoping you've found a solution.
Thanks,
Dale
P.S. Please drop me an email if it's convenient.
Edited by: dale hering on Nov 11, 2008 9:11 PM
Hi Dale,
No, unfortunately I never received a response that addressed my question, or worked this one out. It seems that CR just doesn't do bitwise operations on the report filter which I find very surprising indeed considering the maturity of the product.
If you work it out, please post here.
Best regards,
Rod
Can you base the report on an SQL Command, and do the bitwise AND in the SQL?
If not, this formula should do your specific example (basic syntax):
formula = Remainder(Truncate({field} / 4, 0), 2) = 1
Not nearly as clean as ( AND 4) = 4, but it works... Basically, Truncate is shifting the bits right 2 places, and the Remainder is stripping off the rightmost bit of the shifted value. The divisor in the Truncate function should be the same as you'd use after the AND in your example. Obviously (or maybe not), if you wanted something like ( AND 10) > 0, you'd have to split the formula like:
formula = Remainder(Truncate({field} / 8, 0), 2) + Remainder(Truncate({field} / 2, 0), 2) > 0
so that you are looking at each bit separately.
HTH,
Carl
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.