← Lab
ASTERXOR / Lab

The message that repairs one wrong bit

Three carefully arranged check bits can locate a single error in a seven-bit block. The same decoder becomes misleading when its error assumption is broken.

Seven blue and gold bit markers include one position circled in white.
The encoded value nine, with a marked position illustrating a possible flipped bit.
LabASTERXOR / LEON LEUNG

Flip any one bit in this tiny encoded message, and the original four-bit value comes back.

The experiment uses Hamming(7,4): four payload bits become seven transmitted bits. The extra bits are not a second copy of the message. They enforce overlapping parity checks, whose pattern of disagreement identifies one damaged position. We tested every four-bit message and every possible single-bit flip, then deliberately tried a two-bit error to see where the promise ends.

Redundancy is useful when its arrangement tells you what went wrong.
SEVEN POSITIONS

Put the checks where their addresses matter

Number the positions from one to seven. The check bits occupy positions 1, 2 and 4, while payload bits occupy 3, 5, 6 and 7. Each check watches positions whose binary address contains its corresponding bit. Check 1 watches the odd positions; check 2 watches 2, 3, 6 and 7; check 4 watches 4, 5, 6 and 7.

The encoder sets each check bit so that its watched group contains an even number of ones. This is even parity. The overlapping groups are the important design choice: every position belongs to a different combination of checks. A single changed bit therefore leaves a distinctive pattern rather than merely announcing that something is wrong.

Three overlapping parity-check rows form a unique membership pattern for each bit position.
FIG 01Gold cells indicate which of the seven positions each parity check watches.
READ THE DISAGREEMENT

The failed checks form an address

The local encoding of payload value nine is 0011001, read left to right as positions one through seven. Flip position five and checks 1 and 4 fail, while check 2 still passes. Adding the labels of the failed checks gives 5. The decoder flips that position back, restoring the codeword and extracting the original payload.

This combined check result is called a syndrome. Zero means all three parity equations currently hold. Under the assumed zero-or-one-error model, a nonzero syndrome tells the decoder exactly which position to repair. Notice that an error in a check bit is also repairable; the protection covers all seven positions, not only the four carrying payload.

Three rows show the clean, damaged and corrected codewords.
FIG 02Payload nine is encoded, position five is flipped, and the single-error decoder restores the original seven bits.
TRY EVERY SMALL CASE

A finite promise can be checked completely

There are sixteen possible four-bit messages. The script first decodes all sixteen clean codewords. It then flips each of the seven positions separately for each message, producing 112 single-bit corruption cases. Every one returns the correct payload. These are exhaustive cases for this tiny error model rather than a handful of favourable random examples.

The verification report groups them into two checks: all clean cases and all single-bit cases. It does not inflate the test count by calling each bit flip a separate independent scientific result. The cases establish implementation behaviour over the stated finite domain. They do not measure how often a physical channel makes errors or how a real storage device behaves.

TWO WRONG BITS

The same confidence can repair the wrong place

Now start again from payload nine and flip positions one and two together. Their combined syndrome is 3. The single-error decoder believes position three is damaged and flips it, even though that payload bit was originally intact. The extracted value becomes eight. Three parity checks have not given the decoder enough information to distinguish this event from a single error at position three.

A nonzero syndrome can reveal a failed parity relationship without proving the one-error assumption. Hamming(7,4) has minimum distance three between valid codewords, which supports unique single-bit correction, but this correction procedure can miscorrect two-bit damage. That boundary belongs beside the success count, not in small print after a claim that the message repairs itself.

THE PRICE OF REPAIR

Extra bits buy a specific kind of protection

The message carries three additional bits for every four payload bits. That overhead creates separation between valid codewords, allowing a nearby corrupted word to be assigned back to its intended neighbour when the assumption holds. Different codes and channel models make different bargains about block size, detection, correction and decoding effort.

This article implements only the small binary scheme shown in the figures. It is not a test of QR codes, wireless links, memory hardware or a production error-correction library. Its enduring idea is simple enough to inspect by hand: repeating information is not the only way to add resilience. Carefully overlapping constraints can make a limited error identify its own location.

THE THOUGHT TO TAKE AWAY

A repair promise is only as strong as the error model written next to it.