Lesson
The theory — Hamming Code: Correcting a Bit by Naming Where It Is
A Hamming code adds check bits to data so that one flipped bit can be found and flipped back. Each check bit makes a chosen set of positions hold an even number of ones, a parity check. The decoder repeats the checks on what arrived, and the pattern of failures, the syndrome, read as a binary number, is the position of the wrong bit, 0 meaning none. A check digit can only say that something is wrong; this says where. The extended code adds one bit that makes the whole word even, and then corrects any single flip and detects, without correcting, any two: SECDED.
What each symbol means
dᵢ- the four data bits, at positions 3, 5, 6 and 7
p₁, p₂, p₄- the check bits, each at the position it is named after; p0 is the extended code's overall bit
s- the syndrome, 4s4 + 2s2 + s1, where sk is 1 when circle k holds an odd number of ones on arrival
P- the parity of all eight received bits in the extended code: 1 means an odd number of flips
p- the bit-error rate, the chance that any one bit flips, independently of every other
- Assumes
- Every bit flips independently, with the same probability p. Real channels and memories also fail in bursts, several neighbouring bits at once, and a burst is exactly the multiple flip these codes handle worst.
- Breaks when
- At three flips. The extended code reads three flips as one, because the overall check comes out odd, and corrects a bit that was right: the table of every flip shows all 896 triple flips delivering wrong data with no flag.
Problem solved in full
-
How many check bits does a 64-bit word need? 4 steps
Protect 64 data bits the same way. Press Extended, one flip: four check bits for four data bits, a rate of 50.0%. Find how many check bits one 64-bit word needs for the same promise, any single flip corrected and any two flagged, and what the longer word costs at that preset's p = 0.001.
-
With r checks the syndrome takes 2r values. One has to mean no error and each of the m + r positions needs its own, so 2r ≥ m + r + 1. On the page m = 4, and r = 3 meets it exactly, with no value to spare.
-
For m = 64, six checks give 64 values against the 71 needed; seven give 128, enough for 72. So 71 bits correct any single flip.
-
One overall bit on top makes 72 bits, 8 of them checks, and a rate of 88.9% against the page's 50.0%.
-
The cost is that a longer word collects two flips more often, and two flips are what SECDED can no longer repair. For one 8-bit word that probability is the page's two figures added together.
Answer
Eight check bits, a 72-bit word, rate 88.9%. At p = 0.001 it holds two or more flips with probability 2.44×10⁻³. The same 64 bits as sixteen 8-bit words are lost when any one of them is, 4.46×10⁻⁴. The long word is about 5.5 times as likely to lose its 64 bits, and pays an eighth as many check bits for it.
-
Learning path
Why an algorithm is correct
References (2)
- The code itself, the requirement that the checking number give the position of any single error, the check positions 1, 2, 4 and the reason for them, the extended code that adds double-error detection, and the relay computers that motivated it: R. W. Hamming, "Error Detecting and Error Correcting Codes." Bell System Technical Journal 29(2), April 1950, pp. 147-160. DOI 10.1002/j.1538-7305.1950.tb00463.x
- How Hamming told the story in his later course: a relay computer that could detect an error, retried three times and then dropped the problem, and the question that followed: R. W. Hamming, The Art of Doing Science and Engineering: Learning to Learn, Session 12, "Error-Correcting Codes". Lecture slides, Naval Postgraduate School, Monterey (course delivered 1995).