Power of Two Check

A power of two has exactly one set bit in its binary representation. The value 10 is not a power of two because 10 AND 9 equals 8, not zero. ANDing a number with one less than itself yields zero exactly when the number is a power of two. S…

1 sources - 4 claims

A power of two has exactly one set bit in its binary representation. The value 10 is not a power of two because 10 AND 9 equals 8, not zero. ANDing a number with one less than itself yields zero exactly when the number is a power of two. Subtracting 1 from a power of two flips all bits below its single set bit.