Objective
A power of two has a single 1 bit. That is why n & (n - 1) is 0 only for them, and the check needs no loops or logarithms.
Instructions
- The input is a line with integers separated by spaces.
- Show, one per line,
Yesif the number is a power of two (1, 2, 4, 8…) andNoif it is not. 0 and negatives are not.
1 6 8 0
Yes
No
Yes
No
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise