Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bit-wise math

Status
Not open for further replies.

rhancox

Programmer
Jan 29, 2002
9
US
Does anyone have any suggestions on how to perform bit-wise functions, since AND/OR will only return a boolean answer.

Obviously, I want to check for the existence of a bit within a value. Doing the following, "Flags AND 512" only returns True/False (depending on the contents of Flags) and not a value as a result of ANDing 512 with Flags.

Maybe I'm missing something, but as I've tried to use it they way I think it should work, or the way I'd like it to work, it does not return the expected results.

I've checked every newsgroup I could find and searched the web for CR web sites, and of course, I've searched CR's KB.

Any hints and/or suggestions would be greatly appreciated.

Thanks,

Rob
 
You could re-create the 'bit' in a formula field,
If your_test is true then 1 else 0

Madawc Williams
East Anglia, Great Britain
 
I'm not sure I understand your solution.

I've got a flags value, say 7. I want to see of bit 1, value of 2, is set. With immediate data, the statement looks like this 7 AND 2. If bit 1 is set, the answer is 2.

I want to write a formula in CR that says, IF Flags AND 2 = 2 THEN ..whatever..
 
Rather than posting text descriptions, post example data and expected output.

I'm uncertainm what: "I've got a flags value, say 7. I want to see of bit 1, value of 2, is set."

Where is this bit???

"With immediate data, the statement looks like this 7 AND 2. If bit 1 is set, the answer is 2." means.

Perhaps you want the &?

-k
 
Ok, I've got a field in a record, called Flags. It contains flags that I use in a VB program to set or reset check boxes on a form.

In VB code, I can use this code:

For x = 0 to (chkBoxes.Count - 1)
If Flags AND 2^x THEN
chkBoxes(x).Value = 1
End If
Next x

So now in my CR formula, I'd like to do the same thing, more or less, to display certain things like:

IF {table.Flags} AND 2 = 2 THEN
"Flag is set"

Flags, in binary, will look like this, for example:
100101101
From right to left, bits 0, 2, 3, 5 and 8 are set.

To look for bit 2 (binary value 100) being set, I'd write:

IF Flags AND 4 = 4 THEN "Flag is set"

Or:

100101101 AND 100 = 100

I hope this clarifies things.

Rob
 
No responses since my last post? I hope I didn't offend anyone with my elementary explaination. But I could use an answer.

I've done a lot of research, and I don't see a solution, short of performing some fancy mathematical magic. There doesn't appear to be a simple AND or OR function to use for bit-wise operations. If so, let me know so I can move on.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top