bit-manipulationcoding
A quick power-of-two test
Anonymous
For a positive integer, exactly one bit is set when the value is a power of two. The test is n > 0 and (n & (n - 1)) == 0; subtracting one clears that set bit and turns lower bits on.
0
For a positive integer, exactly one bit is set when the value is a power of two. The test is n > 0 and (n & (n - 1)) == 0; subtracting one clears that set bit and turns lower bits on.
No replies yet.