Numbers and bits · 9 / 15 Exercise Easy

Powers of two

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, Yes if the number is a power of two (1, 2, 4, 8…) and No if it is not. 0 and negatives are not.
Input
1 6 8 0
Output
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