isPow2 = x && !( (x-1) & x );
Algorithm:
If x is a power of two, it doesn't have any bits in common with x-1, since it
consists of a single bit on. Any positive power of two is a single bit, using
binary integer representation.
This means that we test if x-1 and x doesn't share bits with the and operator.
Of course, if x is zero (not a power of two) this doesn't hold, so we add an
explicit test for zero with xx && expression.
Negative powers of two (0.5, 0.25, 0.125, etc) could share this same property
in a suitable fraction representation. 0.5 would be 0.1, 0.250 would be 0.01,
0.125 would be 0.001 etc.
jacob