Re: and_bits() usage

new topic     » goto parent     » topic index » view thread      » older message » newer message
mic_ said...

This is not Java, so

if and_bits( myval, 2 ) then 

would be sufficient. I've never looked at what kinds of optimizations the interpreter does though, so it might remove the equality check automatically.

Yes, if and_bits( myval, 2 ) then is slightly more efficient than if and_bits( myval, 2 ) != 0 then.

But note that both these are testing if any of the required bits are on. As you are testing for only one bit it doesn't matter in this case, but the test was and_bits(myval, 0b11), you would only get a true result if either bit were on. If you needed to test that both were on you need to code and_its(myval, testbits) = testbits.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu