# Calculation in SQLTag

The following equation extracts a bit value (bit 0 in this case) from an word.

``(floor({[.]WordValue}/2^0))%2``

I have been using it successfully for a while to drive a dynamic property, which in turn controls a display color.

However, when I use the same equation as the expression driving a SQLTag value, it only works sporadically (i.e. bit 0 seems to always be right, but bits 1 and 2 are only occasionally right.

I tried enclosing (2^0), in case operators weren’t correctly prioritized, with the same results.

``(floor({[.]WordValue}/(2^0)))%2``

Any ideas why?

I’ll defer the weird behavior to the bigger brains. My suggestion is to use the getbit expression.

Are you sure the floor function isn’t causing the unexpected results?

Why are you dividing by 2^0 (one)? Are you trying to somehow cast the value? I’m confused. I guess modding the value by 2 works to get the least significant bit. It seems more logical to bitwise AND the value with 1.

[quote=“bds”]The following equation extracts a bit value (bit 0 in this case) from an word.

``(floor({[.]WordValue}/2^0))%2``

I have been using it successfully for a while to drive a dynamic property, which in turn controls a display color.

However, when I use the same equation as the expression driving a SQLTag value, it only works sporadically (i.e. bit 0 seems to always be right, but bits 1 and 2 are only occasionally right.

I tried enclosing (2^0), in case operators weren’t correctly prioritized, with the same results.

``(floor({[.]WordValue}/(2^0)))%2``

Any ideas why?[/quote]

Yeah, I’d use the getBit() function, or at least use the right-shift operators and AND it with a bitmask to get only the least significant bit.

The 0 in 2^0 represents the bit #.

getBit(). Works great.