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
Just in case anyone gets here looking for a solution to this issue...
Here it is :
http://nopadolsiri.wordpress.com/2008/12/30/custom-functions-of-bitwise-in-crystal-reports-9/ (don't forget to read the last comment on how to solve a little issue when pasting the formulas to the editor)
Cheers,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One of the UFLs (User Function Libraries) listed at http://kenhamady.com/bookmarks.html adds a BitWiseAnd() function to Crystal Reports. It is a very simple function to implement if you wish to create your own UFL to do the same.
Rod
it's: (Field1 = 4) And (4 = 4)
You were saying:
(Field1 And 4) = 4
...but you have to test each condition separately: Field1 against 4, and 4 against 4.
Hope this helps,
The Panda
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rod
Open Crystal Reports Help from the Help Menu and go to index. Search for the keywords that you require e.g AND Operator.
You would get the detailed description of these out there.
Hope this helps!!
Regards
Sourashree
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rod,
In case you want to perform bitwise 'and' operation you can write formula like this
If {Test field 1} = 4 and {test field 2}= 10 then 1 else 2
It will return 1 only when both the conditions are true and 2 if any one of them or both of them are false.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
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.