Power of Two Check
Exactly one 1 bit, so clearing the lowest one leaves zero.
Decision · step 2 of 3Bit Manipulation: 64 is a power of two
64 and 63 = 0. Clearing the only 1 left nothing, so 64 was a single bit.
What you will see
A power of two has one set bit; clearing it leaves zero.
Cost
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(1) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, run it on your own input, try operations in any order.
Screen readers: Each bit announces its position and value; each step announces the operation and the resulting number in binary and decimal.
Reduced motion: Bits flip with a crossfade; masks appear in place.
Before this
Taught by the same lesson
Bit Manipulation covers these too, in the same run.