IIntel·DSASDE-1Online Assessment
Check if a Number Is a Power of Two (Bit Level)
Problem
Determine whether an integer is a power of two using bit manipulation, no loops or division.
Example
8 -> true, 6 -> false
Constraints
- -2^31 ≤ n ≤ 2^31-1
Approach
n > 0 && (n & (n-1)) == 0. Intel loves bit-level reasoning — explain why it works.
added 6 days ago