Hamming Codes and Single-Bit Error Correction
Hamming codes are a family of error-correcting codes that add parity bits to data so a receiver can detect and correct certain bit errors. The Hamming(7,4) code stores four data bits in a seven-bit code word. Three parity bits are placed at positions 1, 2, and 4, while data bits occupy positions 3, 5, 6, and 7. With this placement, each parity bit checks a different pattern of positions. If one bit flips during storage or transmission, the failed parity checks form a binary syndrome that identifies the bad position.
This is the key idea behind many memory-protection systems. Real ECC memory uses wider codes, often with additional parity to detect double-bit errors, but the same principle applies. Extra check bits are chosen so each possible single-bit error produces a unique signature. The receiver recomputes the checks, converts the syndrome into a bit position, flips that bit, and recovers the original data. Hamming's insight was that parity could locate an error, not merely announce that one occurred.
Manual Encoding Steps
For Hamming(7,4), write the positions as 1 through 7. Positions 1, 2, and 4 are parity positions p1, p2, and p4. Positions 3, 5, 6, and 7 are data positions d1, d2, d3, and d4. The code word order used here is p1 p2 d1 p4 d2 d3 d4. Parity p1 checks positions 1, 3, 5, and 7. Parity p2 checks positions 2, 3, 6, and 7. Parity p4 checks positions 4, 5, 6, and 7. For even parity, each checked group must contain an even number of ones.
Suppose the data bits are 1011, so d1 = 1, d2 = 0, d3 = 1, and d4 = 1. Parity p1 covers p1, d1, d2, and d4. The data bits in that group are 1, 0, and 1, which already contain two ones, so p1 = 0. Parity p2 covers p2, d1, d3, and d4. Those data bits are 1, 1, and 1, which contain three ones, so p2 = 1 to make the group even. Parity p4 covers p4, d2, d3, and d4. Those data bits are 0, 1, and 1, which contain two ones, so p4 = 0. The encoded word is 0110011.
Syndrome Correction
At the receiver, recompute the same parity checks across the received word. If all checks pass, the syndrome is zero and no single-bit error is indicated. If p1's check fails, set syndrome bit 1. If p2's check fails, set syndrome bit 2. If p4's check fails, set syndrome bit 4. Add those values together. A syndrome of 3 means position 3 is wrong. A syndrome of 5 means position 5 is wrong. The position number emerges because each bit position participates in a unique combination of parity checks.
After finding the syndrome, flip that position to correct a single-bit error. If position 3 in 0110011 flips, the receiver sees 0100011. The parity checks fail in the p1 and p2 groups, giving syndrome 1 + 2 = 3. Flipping position 3 restores 0110011, and extracting positions 3, 5, 6, and 7 recovers data 1011. This is why Hamming codes are called single-error-correcting codes.
Limits and Extensions
Plain Hamming(7,4) corrects one bit error but cannot reliably distinguish every two-bit error from a one-bit error. If two bits flip, the syndrome may point to a third position, causing incorrect correction. Systems that need stronger protection add an overall parity bit, producing SECDED behavior: single-error correction and double-error detection. With overall parity, a single-bit error produces a nonzero syndrome and wrong overall parity. A double-bit error produces a nonzero syndrome but overall parity may remain even, so the system can detect that correction is unsafe.
In modern systems, ECC logic is used in DRAM controllers, caches, flash storage, communication links, and safety-critical controllers. Wider codes protect 32-bit, 64-bit, or larger words. Memory controllers often correct single-bit errors silently while logging events for diagnostics. Repeated corrected errors may indicate aging memory, radiation effects, marginal voltage, thermal stress, or signal integrity problems. The small Hamming(7,4) example is the cleanest way to understand the mechanism before studying production ECC schemes.
When using this tool, remember that the injected error position is one-based, matching the standard Hamming position labels. Position 1 is the leftmost parity bit in the displayed code word. Position 0 means no error. The syndrome displayed by the calculator should match the injected position for any single-bit error, and the corrected data should match the original four data bits.
Manual verification is worth practicing because it prevents confusion between data order and code-word order. Write the seven positions, mark the parity groups, and recompute each parity check after injecting an error. The failed check labels add to the bad position. If the syndrome points to a parity bit, only that parity bit is corrected and the extracted data may already be unchanged. If the syndrome points to a data bit, correction is required before the payload is trusted. This position-based method is the foundation for understanding larger parity-check matrices used in practical ECC systems.
Study Notes
Hamming Code Generator and Error Corrector works best when the article is read as a chain of ideas: Manual Encoding Steps, Syndrome Correction, Limits and Extensions. In Hamming Code and Error Corrector, that chain explains the assumptions behind bit positions, table rows, state names, or encoded fields controlled by data bits, parity positions, parity convention, and received codeword. The Hamming Code and Error Corrector inputs are data bits, parity positions, parity convention, and received codeword, and they should be connected to the specific problem before the output is treated as meaningful.
For Hamming Code and Error Corrector, create one valid codeword, flip exactly one bit, compute the syndrome, and verify that the syndrome points back to the flipped position. Next, change one Hamming Code and Error Corrector input from this list: data bits, parity positions, parity convention, and received codeword. Predict the direction of the change before recalculating, especially because Hamming Code and Error Corrector mistakes often come from numbering parity positions from the wrong side of the codeword or interpreting the syndrome backward.
A strong homework or lab note for Hamming Code and Error Corrector should record the bit order or table convention, one worked pattern, and the way data bits, parity positions, parity convention, and received codeword determine the output. If Hamming Code Generator and Error Corrector disagrees with a later hand calculation or lab observation, those Hamming Code and Error Corrector notes make it easier to locate whether the mismatch came from arithmetic, convention, measurement setup, or an input entered in the wrong form.