AlgoScope

Power of Two Check

Exactly one 1 bit, so clearing the lowest one leaves zero.

Bit manipulation, algorithm, beginner
64 has 1 set bits.0001020304051607
64 has 1 set bits.0001020304051607

Bit Manipulation: 64 is a power of two

Decision, step 2 of 3

64 and 63 = 0. Clearing the only 1 left nothing, so 64 was a single bit.

How bit manipulation works

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Space
O(1)

Taught by the same lesson

Bit Manipulation covers these too, in the same run.