Hamming Code (ECC)
As memory systems scale up, bit errors (e.g., due to radiation or electrical noise) become non-negligible. Reliability can be improved by storing redundant check bits alongside data to detect and sometimes correct errors.
Parity check
Section titled “Parity check”Parity adds 1 bit so the total number of 1s satisfies an even/odd constraint. For even parity on data :
Parity is simple, but:
- it detects only odd-number-of-bit flips
- it cannot locate or correct errors
Hamming code
Section titled “Hamming code”Hamming codes can locate and correct single-bit errors.
For data bits and parity bits, a Hamming code needs:
A classic example is Hamming(7,4): 4 data bits + 3 parity bits.
Parity bits are placed at positions (powers of two). Data fills the remaining positions:
| Position | Type | Binary index | Covered by |
|---|---|---|---|
| 1 | 001 | positions with LSB=1: (1,3,5,7) | |
| 2 | 010 | positions with middle bit=1: (2,3,6,7) | |
| 3 | 011 | ||
| 4 | 100 | positions with MSB=1: (4,5,6,7) | |
| 5 | 101 | ||
| 6 | 110 | ||
| 7 | 111 |
Table 7.1: Bit meanings and parity coverage for Hamming(7,4).
With even parity:
On read, compute syndrome from received bits (primes denote received):
If , no error. Otherwise, the binary value of indicates the bit position (1–7) that flipped.
Experiment: Hamming code detection and correction
Section titled “Experiment: Hamming code detection and correction”Objectives
Section titled “Objectives”- Understand redundancy via parity bits.
- Implement Hamming(7,4) encoding and syndrome checking.
- Verify single-bit error correction in a circuit.
Principles
Section titled “Principles”Encode: compute parity bits and assemble the 7-bit codeword. Decode: compute syndrome, locate the error, and flip the indicated bit.
Environment
Section titled “Environment”- Simulator: Logisim Evolution
Task 1: Build a Hamming(7,4) encoder
Section titled “Task 1: Build a Hamming(7,4) encoder”- Inputs:
- Outputs: (7-bit codeword)
- Use XOR gates to generate and assemble bits by position (1…7).
Task 2: Build a single-bit error injector
Section titled “Task 2: Build a single-bit error injector”Use XOR properties: , .
- Split the 7-bit codeword into 7 wires.
- Put an XOR gate on each bit.
- Drive the second XOR input with a control pin (0 = no flip, 1 = flip).
Task 3: Syndrome computation and correction
Section titled “Task 3: Syndrome computation and correction”- Recompute from the injected word.
- Use a 3-to-8 decoder to decode :
- output 0 means “no error”
- outputs 1–7 indicate which bit flipped
- Use another set of XOR gates to flip the indicated bit back.
- Extract corrected data bits as final outputs.
Results
Section titled “Results”- Circuit screenshots (encoder + injector + corrector).
- Demonstrate correction of an injected error at bit position 6.
- Briefly analyze what happens for a double-bit error and why miscorrection can occur.
Questions
Section titled “Questions”- If parity bit flips (bit 1 error), can the circuit correct it? Is that correction meaningful in practice?
- SECDED (single error correction, double error detection) is common in servers. How many additional check bits are needed beyond Hamming(7,4) to detect double-bit errors?