55Technology

How computers fix their own mistakes

A flipped bit can turn one letter into another. See what a noisy wire does, say it three times, add a check bit and find the bad bit with three circles.

Sorting office

A wire that flips bits

Everything a computer stores or sends is a row of bits, each a 0 or a 1. A scratch on a disc, a burst of static on a line or a stray particle can flip a bit. A flipped bit can turn one letter into another. Computers cope by sending a little extra, in a clever way, so that the receiver can tell that something went wrong, and often put it right.

Four things to try. See what a noisy wire does to a letter. Say everything three times and vote. Add one check bit. And find a flipped bit with three circles, the idea of Richard Hamming. The sums are exact, and the page works them out itself. Without a script each part shows one picture or table.

Counter one

The noisy wire

A letter is stored as eight bits. The letter H is 01001000. Suppose each bit on the wire has a small chance of being flipped. The chance that all eight arrive unharmed is one minus that chance, eight times over. With 1 flip in 10, only about 43 letters in 100 arrive intact.

Slide the chance of a flip, then send the letter. Each press uses fresh random flips, so you will see a different result each time.

Sent
01001000
H
Arrived
01001000
H

With a chance of 10% for each bit, all eight bits arrive unharmed 43.0% of the time.

Counter two

Say it three times

The simplest fix is to send every bit three times and let the receiver take a vote. A bit is wrong only if at least two of its three copies flip. With a flip chance of p, that is 3p² minus 2p³ or, in plain numbers, three times p squared, times one minus p, plus p cubed. For small p this is much smaller than p.

Slide the chance of a flip. The price is steep: three times as many bits for the same letter. Better codes pay much less.

Chance that a letter arrives right, without a code and with three copies and a vote
Chance of a flipPlainThree copies
1%92.3%99.8%
5%66.3%94.3%
10%43.0%79.7%
20%16.8%41.5%
  • Plain
  • Three copies

Each row shows the chance that a whole letter arrives right. Three copies use 24 bits instead of 8.

Counter three

One check bit

A cheaper trick adds one bit so that the number of ones is always even. This is a parity bit. If one bit flips, the count turns odd, and the receiver knows something is wrong. But it cannot tell which bit, so it cannot fix it. And if two bits flip, the count is even again and the error slips through.

Press the bits to flip them. Try one flip, then two.

Word
10010000

Press a bit to flip it. The last bit is the check bit.

The letter H is 1001000. It has two ones, so the check bit is 0, and the number of ones is even. If one bit flips, the number turns odd and the receiver knows. It cannot tell which bit.

Counter four

Three circles

In 1950 Richard Hamming, at Bell Labs, published a code that finds and fixes a single flipped bit. He had been working with a relay computer that ran jobs unattended at weekends and simply moved on to the next job when it hit an error. The code takes four bits of message and adds three check bits, seven in all. Each of three circles must hold an even number of ones. When a bit flips, the circles that fail point straight at it.

Set the four message bits. Then press any bit to flip it. The circles that fail turn red, and the decoder puts the bit right. Then try flipping two bits and see what happens.

0p11p21d10p30d21d31d4

The message 1011 is sent as seven bits. Every circle holds an even number of ones. Flip a bit to see the circles that fail.

Key takeaways

  1. Bits get flipped by noise and scratches. Computers send extra bits so the receiver can notice and often fix the damage.
  2. Sending each bit three times and voting turns an error chance of p into 3p² minus 2p³, at three times the cost.
  3. One parity bit detects a single flip but cannot say which bit it was, and misses two flips.
  4. The Hamming code uses three checks for four message bits. The failed checks spell out the place of the flipped bit. It fixes any single flip and fails on two.
  5. Real codes are stronger. A QR code can lose 7 to 30 per cent of its data and still be read, depending on the setting.

Sources

Some of these sites could not be opened while this page was written, so some facts were checked through search results that quote them. Hamming’s code published in 1950 and the story of the relay machine that moved on after errors at weekends, the (7,4) shape, the failed checks pointing at the position of the bad bit, Shannon’s theorem of 1948, the vote of three copies failing with chance 3p² minus 2p³, and the four QR code levels of 7, 15, 25 and 30 per cent each appeared in at least two places. Sources differ on whether the machine read punched tape or punched cards, so the page does not say. The page does not say how much of a disc or a QR code real scratches destroy. The sums for the noisy wire, the vote and the circles are exact and are computed on the page. The parity bit facts are standard coding theory.