# How to do bitwise operations in Crystal Reports 2008

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

##### Carl Sopchak replied

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