📚 Power of Two Detection
A power of 2 has exactly one bit set in its binary
representation:
1 = 00000001 (2⁰)
2 = 00000010 (2¹)
4 = 00000100 (2²)
8 = 00001000 (2³)
...
// n & (n-1) removes the lowest set bit
// If result is 0, there was only ONE bit!
isPowerOf2 = (n > 0) && ((n & (n - 1)) == 0)