Exercises — ECC and memory error correction
Before the drills, two ideas must be pinned down, because every figure and solution leans on them.
With those two ideas in hand, here is the figure we will reuse throughout:

Level 1 — Recognition
(Can you spot the right term / read a formula off by heart?)
L1.1
A DRAM cell silently holds the wrong value after a cosmic-ray neutron hits it, but the chip still works fine. What is this called, and what is it not?
Recall Solution
It is a soft error (a transient bit flip). It is not a hard error — the hardware is undamaged, and rewriting the cell fixes it. See Cosmic Rays and Soft Errors and DRAM.
L1.2
A code has minimum distance . Without building anything, state how many errors it can detect and how many it can correct.
Recall Solution
Detect . Correct .
L1.3
In a Hamming code, at which bit positions do the parity bits live? Name the first four.
Recall Solution
At powers of two: positions . Everything else holds data. (Position counting starts at 1.)
Level 2 — Application
(Plug into the machinery and turn the crank.)
L2.1
You must protect data bits. Find the smallest number of parity bits that satisfies the Hamming bound, and hence the total codeword length .
Recall Solution
The Parity Bit-counting bound is .
- : ? No.
- : ? Yes. So , and . This is the famous Hamming(7,4) code.
L2.2
Encode the data bits 1010 with Hamming(7,4), even parity. Give the 7-bit codeword.
Recall Solution
Lay data into the non-power-of-two slots. Positions : Apply the parity-check rule (XOR of covered bits , so each parity = XOR of the data it covers):
- covers positions ; data there are → .
- covers positions ; data there are → .
- covers positions ; data there are → . Codeword (positions 1→7): . Check: each covered set now XORs to . ✓
L2.3
Take the codeword you just built, 1011010, and flip position 6. Decode it: compute the syndrome and recover the original.
Recall Solution
Flipped word: position 6 was 1 → now 0: .
Recompute each syndrome bit ("ok" if XOR = 0):
- : positions → (ok).
- : positions → (fail).
- : positions → (fail).
Syndrome . So position 6 is wrong — matches our flip. Flip it back → , and the data slots read back
1010. ✓
Level 3 — Analysis
(Why does the machinery behave this way? Probe the edges.)
L3.1
A single parity bit gives . Using the capability formulas, prove it can detect one error but correct zero. Then say why we bother with it at all.
Recall Solution
Detect: . Correct: . Why zero correction: with , a single flip sits exactly halfway between two codewords — there is no unique nearest neighbour to snap to. You know something broke but not where. Still useful: cheap detection lets a system re-fetch/retry, which is far better than silent corruption.
L3.2
In Hamming(7,4) you compute the syndrome and get . Then separately you're told two bits actually flipped. Explain, using the "ball" picture, why the decoder is now wrong — and what the syndrome would look like.
Recall Solution
A pure Hamming(7,4) has , so its balls have radius . Two flips push you a distance 2 from your codeword — outside your own ball, and possibly inside a neighbour's ball (its decoding region).
- If the two flips land you exactly on another legal codeword, the recomputed syndrome is → decoder says "no error" (silent miscorrect). This is exactly why raw Hamming(7,4) is unsafe for 2 errors.
- More often the syndrome is nonzero but points at a third, innocent position (you have drifted into a neighbour's decoding region) → the decoder "corrects" a bit that was fine, making things worse. The picture: two hops leave the safe radius-1 zone, so nearest-neighbour logic can no longer be trusted.
L3.3
Given the Hamming bound , find the largest number of data bits that Hamming parity bits can protect for single-error correction. Then reconcile this with real ECC DRAM, which uses 7 Hamming bits + 1 overall parity bit.
Recall Solution
Pure single-error-correcting count. With Hamming check bits (all of them addressing the syndrome), the bound is (total ). This is a code — correct 1, no double-detect. Real ECC DRAM is different in how it spends its 8 bits. It does not use 8 Hamming bits. It uses 7 Hamming check bits (enough to address the syndrome for : ✓) plus 1 overall parity bit that upgrades the code to (SECDED). Total ECC width bits, giving the familiar 72-bit-wide DIMM ( data ECC). The key distinction: the "8 ECC bits" of DRAM are not 8 syndrome-addressing Hamming bits — they are Hamming overall. Conflating "total ECC bits" with "Hamming bits" is the trap the next callout addresses.
Level 4 — Synthesis
(Assemble the parts into a new working code.)
L4.1
Upgrade Hamming(7,4) to SECDED by adding an overall parity bit over all 7 bits (even parity), making an 8-bit word. Encode data 1010 (whose Hamming(7,4) codeword you found in L2.2 was 1011010) and give the full 8-bit SECDED word.
Recall Solution
Hamming codeword: — count the ones: (even). Overall parity XOR of all 7 bits (even count → 0). 8-bit SECDED word (put first): . Now the code has : correct, detect (in particular all doubles).
L4.2
Using your L4.1 word 0 1011010 ( then positions 1–7), corrupt it with a double error: flip positions 3 and 6. Run the SECDED decode logic and show it correctly refuses to miscorrect.
Recall Solution
Original: , body .
Flip pos 3 (1→0) and pos 6 (1→0): body becomes , unchanged .
Hamming syndrome on the body:
- : pos (fail).
- : pos (ok).
- : pos (fail). Syndrome . Overall-parity check : XOR of all 8 bits ( + body). Count of 1s → even, so (ok). Full SECDED decode table (all four quadrants):
| syndrome | overall parity | verdict |
|---|---|---|
| ok () | no error | |
| wrong () | the overall-parity bit itself flipped → correct | |
| wrong () | single error at syndrome position → correct it | |
| ok () | double error → detect only, do NOT correct |
We are in the last row: syndrome but overall parity even/OK → double error detected, uncorrectable → raise alarm. The decoder correctly does not touch position 5 (which was never flipped). ✓ (The new second row matters: if only flips, the body's Hamming syndrome is but is wrong — so we know the lone bad bit is and simply flip it back.)
Level 5 — Mastery
(Design decisions, trade-offs, and one contest-grade problem.)
L5.1
A designer proposes protecting a 64-bit word by simply repeating each bit 3 times (192 bits total). Compare its correction power and overhead against SECDED(72,64). Which wins for DRAM and why?
Recall Solution
Triple repetition (majority vote): each triple has → error corrected per triple. Overhead: redundant bits = 200% overhead. It can correct up to one flip in every group, so many total errors — but at ruinous cost. SECDED(72,64): ECC bits ( Hamming overall) → 12.5% overhead, corrects 1 and detects 2 per 64-bit word. Winner for DRAM: SECDED, overwhelmingly. Soft errors are rare per word; single-error correction covers the common case at the storage of repetition. Repetition only pays off in extreme radiation environments where multi-bit-per-word errors are expected. For chip-failure resilience you instead move to Reed-Solomon Codes-style Chipkill, not naive repetition.
L5.2
Contest problem. You receive a Hamming(7,4) word (even parity, no overall bit) and read . (a) Is there an error? (b) If so, where, and what is the corrected codeword? (c) Extract the original 4 data bits.
Recall Solution
Body positions 1–7: .
- : pos (ok).
- : pos (fail).
- : pos (fail).
Syndrome . (a) Yes, an error at position 6.
(b) Flip position 6 (
1→0): corrected word . Verify: pos; pos; pos. Syndrome ✓. (c) Data slots are positions → .
L5.3
Prove the general claim behind Hamming Code: with parity bits placed at powers of two, the syndrome equals the binary index of the single flipped position. (One-paragraph argument.)
Recall Solution
Assign each position its binary expansion. Parity bit is defined to check exactly the positions whose index has bit set. If position flips, then syndrome bit changes value iff bit of is (that flip is inside 's coverage precisely when bit of is set). So the vector of failing checks reads out, bit by bit, the binary digits of — i.e. syndrome . If nothing flipped, every check passes → syndrome , reserved for "no error." This is why the placement must be powers of two: they make each check correspond to one independent binary digit of the address, and it is why nonzero syndromes name exactly positions (the Hamming bound).
Active-recall flashcards
For data bits, how many Hamming parity bits are needed?
Encode 1010 in Hamming(7,4) even parity.
1011010.