ViewWiki

Lesson 5 of 5

Hamming's code.

About 25 minutes · 6 practice questions

Three overlapping parity checks find which bit flipped and repair it: how to read them as a number in base 2, what happens when two bits flip, and what it costs.

Step 1 of 6 · Three overlapping checks

Step 1 of 6

Three overlapping checks

In 1950 Richard Hamming published a code that does not just catch a flip, but finds it. The Hamming (7,4) code adds three parity bits to every four data bits, making blocks of seven. Number the positions in a block from 11⁠ to 77⁠. The parity bits sit in positions 11⁠, 22⁠ and 44⁠, and each belongs to a different check:

  • Check A covers positions 11⁠, 33⁠, 55⁠ and 77⁠.
  • Check B covers positions 22⁠, 33⁠, 66⁠ and 77⁠.
  • Check C covers positions 44⁠, 55⁠, 66⁠ and 77⁠.

Each parity bit is set so that its check holds an even number of 1s. On the board above the line the checks are drawn as three overlapping circles, and each position has a region of its own.

Here the line is perfectly quiet, and Faulty bit picks one position that flips in every block, as if one wire in the cable were broken. This time it is position 66⁠.

To the question

Step 2 of 6

Reading the checks

When one bit flips, every check that covers it fails, and the others pass. The checks were chosen so that this pattern is the position itself, written in base 2: check A is the ones digit, B the twos digit, and C the fours digit. So read them in the order C B A and write 11⁠ for each check that failed. That number is called the block’s syndrome, and 00⁠ means every check passed.

Now Faulty bit is hidden, and Look inside is closed.

To the question

Step 3 of 6

Parity bits flip too

The noise does not know which bits are data and which are parity: a parity bit can flip on the way too. Positions 11⁠, 22⁠ and 44⁠, the powers of 22⁠, are exactly the positions inside one circle only. Flipping one of them fails only its own check, and the syndrome points to it like any other position.

To the question

Step 4 of 6

Two flips

Look inside is open at Repaired: the receiver flips the bit the syndrome points to, and the display shows the repaired text. The line is noisy again, 5% per bit. The code assumes that at most one bit flips in each block. When two flip, what the receiver sees is the pattern of a single flip, somewhere else.

To the question

Step 5 of 6

How often the code fails

With the code, a block arrives wrong only if two or more of its seven bits flipped. The counter compares the last 5050⁠ blocks with and without the code.

To the question

Step 6 of 6

The price

Three bits out of every seven on the line carry no part of the message. That is the price of repair: the line carries data at only 47\tfrac47⁠ of its rate. Modern codes, in phones, on CDs and on spacecraft, repair far more errors at a lower price, but their idea is the same: overlapping parity checks whose answers together point to the error.

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Predict, then look

The line is perfectly quiet, but Faulty bit is 6: in every block the bit in position 6 flips. Which of the checks A, B and C will fail? Choose, and then Look inside moves to Parity checks.

To the experiment

Practice · Calculate

A new fault on the line, and this time you are not shown where. In every block checks A and B fail, and check C passes. In which position does the bit flip?

To the experiment

Practice · Reach the target

Change Faulty bit until only check C fails, while A and B pass. Press Check.

To the experiment

Practice · Choose

In one block two bits flip, in positions 3 and 5. What does the receiver do?

To the experiment

Practice · Calculate

Chance a bit flips is fixed at 5%, and the code repairs. A coded block arrives wrong only if two or more of its seven bits flipped. What is the chance of that? Answer in per cent.

To the experiment

Practice · Calculate

The message HELLO is five characters, eight bits each, sent in blocks of four bits. How many bits does one copy of it take on the line with Hamming’s code?