The lit switches add up: 32 + 8 + 2 = 42. Tap any switch to flip that bit.
↑ read the remainders bottom-to-top
result — 42 in binary
verify: 32 + 8 + 2 = 42
keeps a bit only when BOTH A and B have 1 in that position
Even / odd check
Instead of n % 2 == 0, low-level code writes (n & 1) == 0. The last bit of any even number is always 0.
Power-of-two check
n & (n - 1) == 0 — a power of 2 has exactly one 1-bit. Subtracting 1 flips every bit below it, so AND gives 0.
File permission flags
chmod 755 is bitwise flags. Read = 4, Write = 2, Execute = 1. OR them together: 4 | 2 | 1 = 7, full access.
RGB colour masking
Pull red out of 0xFF5733 with (color >> 16) & 0xFF = 255. Every browser and image editor does this.
Multiply / divide by 2, fast
n << 1 is n × 2 and n >> 1 is n ÷ 2. Compilers lean on this internally for speed.
Interview patterns
Single number, counting bits, missing number, subset generation — all lean on XOR or AND. Once you see the pattern they get straightforward.