Problem Description

Check if number is power of 2 using single bitwise operation.
Real Life: Powers of 2 are special in computing (2, 4, 8, 16...).

Step-by-Step Logic:
1. Power of 2 has only one set bit (100, 1000, 10000)
2. n-1 flips all bits after that single 1
3. n & (n-1) will be 0 for power of 2
4. Single operation check

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next