cancel
Showing results for 
Search instead for 
Did you mean: 

How to do bitwise operations in Crystal Reports 2008

rod_weir
Explorer
0 Kudos

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

View Entire Topic
rod_weir
Explorer
0 Kudos

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

Former Member
0 Kudos

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

rod_weir
Explorer
0 Kudos

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

Former Member
0 Kudos

If you ever find a solution, i have the same problem.

Thank You

DenisL

rod_weir
Explorer
0 Kudos

Just thought I would post that I still haven't figured this one out.

Does anyone know how to do bitwise operations in Crystal Reports?!

Many thanks,

Rod

Former Member
0 Kudos

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

rod_weir
Explorer
0 Kudos

Hi Carl,

Thanks for your example code - makes sense. I'll have a go at it.

Best regards,

Rod