A logbook for curious waters
← All Reckonings

The Daily Reckoning

How Can Seven Bits Repair One Broken Bit?

Three overlapping parity checks do more than notice a flipped bit: their pattern names the exact position to repair.

Difficulty
Intermediate
Area
Discrete mathematics and computation
Reading time
9 minutes
Prerequisites
Binary digits · Even and odd numbers · Powers of two
Seven luminous binary nodes cross a dark maritime blueprint. Three overlapping parity routes converge on a fractured sixth node, while a precise 110 base-two signal points to the damaged position.

A machine sends four binary digits:

1011.1011.

During storage or transmission, one digit flips. A 11 becomes 00, or a 00 becomes 11. If the receiver sees only the damaged four digits, the receiver cannot know which digit changed—or even whether anything changed.

Add three carefully chosen digits before sending, however, and the seven-digit block can repair any one flipped digit by itself. The extra digits do not copy the message. They answer three overlapping yes-or-no questions whose combined answer identifies the damaged position.

Three questions can name eight outcomes

A single parity bit records whether a group contains an even or odd number of 11s. Under the even-parity convention, the parity bit is chosen so that the entire group contains an even number of 11s. If one digit in the group flips, the group’s parity changes from even to odd.

One parity check can say only “pass” or “fail.” Three checks can produce

23=82^3=8

different patterns. That is exactly enough for eight possibilities: no error, or an error in one of seven positions.

The Hamming (7,4)(7,4) code turns four data bits into a seven-bit codeword. Positions 11, 22, and 44 hold parity bits. Positions 33, 55, 66, and 77 hold the four data bits. The three parity checks cover these positions:

check 1: 1,3,5,7,check 2: 2,3,6,7,check 4: 4,5,6,7.\begin{aligned} \text{check 1: }&1,3,5,7,\\ \text{check 2: }&2,3,6,7,\\ \text{check 4: }&4,5,6,7. \end{aligned}

The check numbers 11, 22, and 44 are powers of two. Write every position from 11 through 77 in three-digit binary form:

1=0012, 2=0102, 3=0112,…, 7=1112.1=001_2,\ 2=010_2,\ 3=011_2,\ldots,\ 7=111_2.

The binary label tells you which checks watch that position. Position 66 has label 1102110_2, so checks 44 and 22 watch it, while check 11 does not.

The interactive diagram below begins with the valid codeword 01100110110011. Select any position to flip its bit. The diagram keeps to Hamming’s promise that at most one position is damaged at a time.

Interactive error-correcting code

Flip one bit, then let three parity checks find it

Check 1positions 1, 3, 5, 7
0 · passes
Check 2positions 2, 3, 6, 7
0 · passes
Check 4positions 4, 5, 6, 7
0 · passes
Syndrome, read as check 4 · check 2 · check 1000₂ = 0

All three checks pass. The codeword is clean.

What to notice: each position's small three-digit label says which parity checks watch that position. Flip position 6, whose label is 110, and checks 4 and 2 fail while check 1 passes. The syndrome is therefore 110 in base two, which is 6.

The three check results form a syndrome. Read the results in the order check 44, check 22, check 11. A passing check contributes 00 and a failing check contributes 11. The syndrome 1102110_2 is the binary representation of 66, so it names position 66.

The rule in one matrix

Let

r=(r1,r2,r3,r4,r5,r6,r7)\mathbf r=(r_1,r_2,r_3,r_4,r_5,r_6,r_7)

be the seven received bits, where rjr_j is the bit in position jj. Addition is performed modulo 22, so 1+1=01+1=0. Equivalently, addition is the exclusive-or operation, written ⊕\oplus.

The parity-check matrix is

H=(101010101100110001111).H= \begin{pmatrix} 1&0&1&0&1&0&1\\ 0&1&1&0&0&1&1\\ 0&0&0&1&1&1&1 \end{pmatrix}.

The first row marks the positions watched by check 11; the second marks check 22; the third marks check 44. The syndrome vector is

s=HrT(mod2).\mathbf s=H\mathbf r^{\mathsf T}\pmod 2.

Here, rT\mathbf r^{\mathsf T} means the received row of bits written as a column. Each column of HH is the three-digit binary label of its position, read from bottom to top when the syndrome is displayed as s4s2s1s_4s_2s_1. If bit jj alone flips, the syndrome becomes column jj of HH. The location is built into the matrix.

Worked example: encode, damage, repair

Encode the data word 10111011. Put its digits into positions 33, 55, 66, and 77:

position1234567valuep1p21p4011\begin{array}{c|ccccccc} \text{position}&1&2&3&4&5&6&7\\ \hline \text{value}&p_1&p_2&1&p_4&0&1&1 \end{array}

The symbols p1p_1, p2p_2, and p4p_4 denote the parity bits.

For check 11, the data bits in positions 33, 55, and 77 are 11, 00, and 11. They already contain two 11s, so choose p1=0p_1=0:

p1⊕1⊕0⊕1=0.p_1\oplus1\oplus0\oplus1=0.

For check 22, the data bits in positions 33, 66, and 77 are all 11. Three is odd, so choose p2=1p_2=1 to make the total even:

p2⊕1⊕1⊕1=1⊕1⊕1⊕1=0.p_2\oplus1\oplus1\oplus1=1\oplus1\oplus1\oplus1=0.

For check 44, positions 55, 66, and 77 contain 00, 11, and 11. Two 11s are already even, so p4=0p_4=0:

p4⊕0⊕1⊕1=0.p_4\oplus0\oplus1\oplus1=0.

The complete codeword is therefore

0110011.0110011.

Suppose position 66 flips from 11 to 00. The receiver gets

0110001.0110001.

Now evaluate all three checks:

s1=r1⊕r3⊕r5⊕r7=0⊕1⊕0⊕1=0,s2=r2⊕r3⊕r6⊕r7=1⊕1⊕0⊕1=1,s4=r4⊕r5⊕r6⊕r7=0⊕0⊕0⊕1=1.\begin{aligned} s_1&=r_1\oplus r_3\oplus r_5\oplus r_7 =0\oplus1\oplus0\oplus1=0,\\ s_2&=r_2\oplus r_3\oplus r_6\oplus r_7 =1\oplus1\oplus0\oplus1=1,\\ s_4&=r_4\oplus r_5\oplus r_6\oplus r_7 =0\oplus0\oplus0\oplus1=1. \end{aligned}

Thus

(s4s2s1)2=(110)2=6.(s_4s_2s_1)_2=(110)_2=6.

Flip position 66 back to 11. The repaired codeword is 01100110110011, and its data positions once again read 10111011.

Try two transmissions

Problem 1

Encode the data word 11011101 by placing its digits in positions 33, 55, 66, and 77. Use even parity. What seven-bit codeword do you obtain?

Reveal the solution

Start with

position1234567valuep1p21p4101.\begin{array}{c|ccccccc} \text{position}&1&2&3&4&5&6&7\\ \hline \text{value}&p_1&p_2&1&p_4&1&0&1. \end{array}

Check 11 sees positions 33, 55, and 77, which contain three 11s. Set p1=1p_1=1 to make the total even.

Check 22 sees data values 11, 00, and 11 in positions 33, 66, and 77. Two 11s are even, so p2=0p_2=0.

Check 44 sees data values 11, 00, and 11 in positions 55, 66, and 77. Again the total is even, so p4=0p_4=0.

The codeword is

1010101.1010101.

Problem 2

The codeword from Problem 1 is sent, but the receiver gets 10100011010001. Find the syndrome and repair the error.

Reveal the solution

Compute the three checks:

s1=1⊕1⊕0⊕1=1,s2=0⊕1⊕0⊕1=0,s4=0⊕0⊕0⊕1=1.\begin{aligned} s_1&=1\oplus1\oplus0\oplus1=1,\\ s_2&=0\oplus1\oplus0\oplus1=0,\\ s_4&=0\oplus0\oplus0\oplus1=1. \end{aligned}

The syndrome is

(s4s2s1)2=(101)2=5.(s_4s_2s_1)_2=(101)_2=5.

Position 55 is wrong. Flip its 00 back to 11 to recover 10101011010101.

A lost weekend becomes a new subject

Richard Hamming arrived at Bell Telephone Laboratories in 1946 after running computing machines for the Manhattan Project at Los Alamos. The wartime work did not dictate the code, but it placed Hamming among a postwar movement of mathematicians who treated reliable large-scale computation as a serious research problem.

At Bell Labs in 1947, Hamming left a calculation running over a weekend. An error stopped the machine, and he returned on Monday to find no useful result. The University of St Andrews’ biography of Hamming records the question that followed: if a machine could detect an error, why could it not locate and correct the error?

Hamming was not working in isolation. He shared Bell Labs’ mathematical research environment with Claude Shannon and John Tukey. Shannon’s 1948 paper “A Mathematical Theory of Communication” established a general theory of communication through noisy channels. Hamming attacked one constructive part of that larger problem: how a finite pattern of redundant symbols could correct mistakes efficiently.

Hamming’s “Error Detecting and Error Correcting Codes” appeared in the Bell System Technical Journal in April 1950. The paper defined the distance between two binary words as the number of positions where they differ, now called Hamming distance. Valid Hamming (7,4)(7,4) codewords are at least three flips apart. A received word one flip from a valid codeword therefore has one unambiguous nearest codeword.

What the guarantee does—and does not—cover

Distance three guarantees correction of any one-bit error. The same distance can instead guarantee detection of any two-bit error, because two flips cannot turn one valid codeword into another. A basic Hamming decoder cannot reliably do both jobs at once: two flipped bits can produce a syndrome that impersonates a one-bit error at a third position.

Adding one overall parity bit creates an extended Hamming code with distance four. That version supports single-error correction and double-error detection, usually abbreviated SECDED. Infineon’s documentation for static random-access memory describes how error-correcting circuitry stores parity alongside each data word and repairs a single-bit fault as the word is read.

The seven-bit code in this lesson is small enough to inspect by hand. Practical memory systems use wider codewords and hardware designed around the same ideas. Communications systems also add structured redundancy, although modern channels often use stronger descendants such as Bose–Chaudhuri–Hocquenghem, Reed–Solomon, low-density parity-check, or polar codes when many errors or long blocks must be handled.

One idea to remember

Redundancy can carry an address. Hamming’s three parity bits do more than announce that a bit changed: the pattern of failed checks is the binary number of the position to repair.

A useful next step is to derive why rr parity bits support a Hamming code of length 2r−12^r-1, or to study Hamming distance as a geometry of binary words. For another compact binary cycle, revisit why a prime makes giant powers loop.

Sources