Hamming Codes and Self-Correcting Bits
Richard Hamming’s 1950 codes added parity bits to data so a receiver could detect and correct a single flipped bit. Toggle four data bits, flip any of the seven encoded bits, and watch the syndrome reveal the error position.
even parity · syndrome = XOR of positions with a 1 = 0 → no error detected
Four data bits are placed at positions 3, 5, 6, and 7. Parity bits at 1, 2, and 4 are computed with even parity. Click any encoded bit to inject a single error; the syndrome is the XOR of the positions holding a 1, which directly names the corrupted position. If two bits flipped at once, the syndrome would point at a third position — that is why Hamming(7,4) only guarantees single-bit correction.
What you are seeing
Four data bits sit at positions 3, 5, 6, and 7 of a 7-bit word. Positions 1, 2, and 4 hold parity bits computed from overlapping subsets.
Each parity bit makes its subset have even parity. When a bit flips, the subsets containing it break parity.
The syndrome is the XOR of the positions holding a 1. A nonzero syndrome names the corrupted position, so flipping it back repairs the word.
Why it matters
Error-correcting codes keep data intact in memory, storage, and communication. Hamming’s idea is the ancestor of the ECC in RAM and the coding schemes used in networking and space probes.
Complexity & details
Encoding and syndrome checking are O(n) for n = 7 bits. Correcting one error is O(1) after the syndrome is known.
Frequently asked questions
Can it fix two flipped bits?+
No. With two flipped bits the syndrome is the XOR of two positions, which points somewhere else, so the correction can be wrong. Hamming(7,4) guarantees only single-bit correction, though it can detect some double-bit errors.
Why are parities at positions 1, 2, and 4?+
Those are the powers of two, so their binary representations are single 1 bits. Grouping positions by which of these bits is set makes the syndrome equal to the error position.