Skip to content

Power of Two

EasyBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.

Return true if the integer n is a power of two (1, 2, 4, 8, ...), otherwise false. Try to do it without a loop.

n = 16  →  true    (2^4)
n = 1   →  true    (2^0)
n = 6   →  false
n = 0   →  false

Constraints

  • -2^31 <= n <= 2^31 - 1