A power of two has exactly one 1 bit in its binary representation. You already know a trick to count 1 bits: flips the rightmost 1 to 0.
If is a power of two, it has one 1 bit. Flipping that bit gives 0. So if and only if is a power of two (and , because 0 is not a power of two).
Example: . . . For : . . This test is and uses one bitwise operation.