Module 1 · Place value
A byte is 8 light switches
💡 Light switches: each of the 8 switches has a value — the rightmost is 1, and every switch to the left is worth double. Drag the slider or tap a switch to flip it, and watch the lit values add up to the number.
The lit switches add up: 32 + 8 + 2 = 42. Tap any switch to flip that bit.
Module 2 · Conversion
Decimal → binary, by hand
➗ Keep halving: divide by 2 over and over and write down each remainder. Read those remainders from the bottom up and you have the binary number. The trace below runs the real division so it always matches.
↑ read the remainders bottom-to-top
result — 42 in binary
verify: 32 + 8 + 2 = 42
Module 3 · Operators
The bitwise playground
🎛️ Column by column: line up two bytes and compare them one switch at a time. AND keeps a switch on only if both are on, OR if either is on, XOR only if they disagree. Shifts slide the whole row left or right.
keeps a bit only when BOTH A and B have 1 in that position
Module 4 · In the wild
Where you actually meet bitwise code
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.
Where this connects
🔗 Looking forward: hashing, hash-set membership, and bitmasks in dynamic programming all reuse this exact switch-flipping. Once a byte feels like eight switches, those topics stop looking like magic.