Mental Model
Bit manipulation changes numbers by working directly on their 0s and 1s. It uses simple rules to combine or flip bits quickly.
Analogy: Imagine a row of light switches (bits) that can be ON (1) or OFF (0). Bit operations are like flipping, combining, or shifting these switches to get new patterns.
Number 6 in bits: 0 1 1 0 Positions: 3 2 1 0 AND: 1 & 0 = 0 OR: 1 | 0 = 1 XOR: 1 ^ 0 = 1 NOT: ~0 = 1 (flip all bits) Left Shift: move bits left, add 0 on right Right Shift: move bits right, drop bits on left
