Re: and_bits() usage

new topic     » goto parent     » topic index » view thread      » older message » newer message
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. smile

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 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu