Encode an 8-bit byte: 1011 0101 — Hamming code

exam standardoverhead falls as the block grows

Answer

001101100101

Why this example is worth doing

Eight data bits need four parity bits, giving a (12,8) code — fifty per cent overhead against the (7,4) code's seventy-five. The page tabulates the overhead as the block length grows and makes the general point that longer blocks are more efficient but more fragile, because the single-error guarantee applies per block. Choosing a block length is a trade between overhead and the expected error rate.

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 (12,8) encode

Hamming (12,8): 4 parity bits, because 2^4 = 16 ≥ k + r + 1 = 13.

Data word10110101

Parity bits occupy the power-of-two positions; the payload fills the rest in order. — Hamming (12,8) encode
PositionBinary indexHoldsBit
10001p10
20010p20
30011d11
40100p41
50101d20
60110d31
70111d41
81000p80
91001d50
101010d61
111011d70
121100d81

Each parity bit is the XOR of the data bits it covers, so every check comes out even.

p11 ⊕ 0 ⊕ 1 ⊕ 0 ⊕ 0 = 0covers positions 3, 5, 7, 9, 11

p21 ⊕ 1 ⊕ 1 ⊕ 1 ⊕ 0 = 0covers positions 3, 6, 7, 10, 11

p40 ⊕ 1 ⊕ 1 ⊕ 1 = 1covers positions 5, 6, 7, 12

p80 ⊕ 1 ⊕ 0 ⊕ 1 = 0covers positions 9, 10, 11, 12

Codeword001101100101Highlighted cells are parity bits.

Warning:

Positions are 1-indexed: the first character of the codeword is position 1.

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)