Former Member

### 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

10|10000 characters needed characters exceeded

Former Member
Sep 16, 2008 at 02:27 PM

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

10|10000 characters needed characters exceeded
• Former Member Former Member

Hi Carl,

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

Best regards,

Rod

• Former Member
Sep 16, 2008 at 08:29 AM

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

10|10000 characters needed characters exceeded
• Former Member
Sep 16, 2008 at 09:50 AM

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

10|10000 characters needed characters exceeded
• Former Member
Sep 16, 2008 at 01:28 PM

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

10|10000 characters needed characters exceeded
• Former Member
Jan 23, 2013 at 03:27 PM

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,