Corrupt bit 5 of 0110011 and decode — Hamming code

introthe syndrome is the error position

Answer

syndrome = 5, single error corrected

Why this example is worth doing

Flip one bit and recompute the three parity checks: the failing checks, read as a binary number, give the position of the flipped bit directly. That is the whole elegance of the code, and it works because position p is covered by exactly the parity bits whose positions appear in p's binary expansion. The tool lets you flip any bit and watch the syndrome track it, which makes the property obvious in a way the algebra does not.

Try your own input in the Hamming code. Encode, inject an error, and watch the syndrome point straight at the flipped bit.

How the answer is reached

Hamming (7,4) decode

Received0110111Highlighted cells are parity bits.

Each check XORs its coverage set, the parity bit included. — Hamming (7,4) decode
CheckParity bitPositions checkedResult
s0p11, 3, 5, 71 (fails)
s1p22, 3, 6, 70 (passes)
s2p44, 5, 6, 71 (fails)

p1 check0 ⊕ 1 ⊕ 1 ⊕ 1 = 1checks positions 1, 3, 5, 7

p2 check1 ⊕ 1 ⊕ 1 ⊕ 1 = 0checks positions 2, 3, 6, 7

p4 check0 ⊕ 1 ⊕ 1 ⊕ 1 = 1checks positions 4, 5, 6, 7

Syndrome S101₂ = 5read with s₀ as the least significant bit

Syndrome 5 = 101₂, so position 5 is wrong — flip it.

Corrected0110011Highlighted cells are parity bits.

Data word1011

Warning:

A single-error-correcting code cannot tell a double error from a single error; the syndrome then points at an innocent bit.

Source: R. W. Hamming, Bell System Technical Journal 29(2):147–160 (1950)

Compare with

Open this example in the Hamming code

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Hamming positions are numbered from 1 at the left, and parity bits sit at the powers of two — positions 1, 2, 4, 8.

Sources

  • Hamming, “Error Detecting and Error Correcting Codes” (1950)