Re: and_bits() usage
- Posted by jaygade Oct 07, 2009
- 1126 views
euphoric said...
I have a binary value such as this:
myval = 1010
and want to know if the second bit is set. Am I supposed to do this:
if and_bits( myval, 2 ) = 2 then ... end if
or what?
There's gotta be a better way.
Umm, wouldn't it be:
myval = 0b0101 -- assuming 4.0+ if and_bits(myval, 0b10) != 0 then ... end if
In decimal it would be like this:
myval = 5 -- 0101 binary if and_bits(myval, 2) != 0 -- 5 and 2 is equal to 0101 and 0010 is equal to 0 ... end if