Check if a Number Is a Power of Two (Bit Level)

Problem Determine whether a given integer is a power of two, using bit manipulation — no loops and no division.

Input / Output

  • Input: integer n.
  • Output: boolean — true iff n is a power of two.

Constraints

  • -2^31 ≤ n ≤ 2^31 − 1.
  • No loops, no division/modulo.

Example

  • 8 → true; 6 → false; 1 → true; 0 → false; -4 → false.
added …
LeaderboardSalaryAccount