Alternating Bits
easyCheck if binary has alternating bits (101010...)
Alternating Bits
Key Insight
n ^ (n >> 1) should be all 1s if bits alternate. Check (x & (x+1)) == 0.
Step 1Problem
5
5
=0
0
0
0
0
1
0
1
76543210
101 - alternating?
Does 5 (101) have alternating bits?
1 / 5