1001Ferramentas
🛡️ Dev

Hamming Code (7,4) Generator

Encode 4 data bits into 7 Hamming bits with parity, capable of correcting 1 wrong bit. Also demonstrates error detection.

Encoded (p1 p2 d1 p3 d2 d3 d4):
Received (after the error):
Syndrome:
Faulty bit detected:
Corrected:

Hamming (7,4): fixing one wrong bit without asking again

The Hamming code solves a specific problem: detecting and correcting a single flipped bit without needing anything resent. It does this by adding parity bits at deliberately chosen positions — the powers of two. In the (7,4) version, four data bits become seven transmitted bits, with three parity bits at positions 1, 2 and 4.

Type the four data bits and the page shows the encoded word. By choosing to inject an error at any position from 1 to 7, you see what arrives at the other end, the syndrome the receiver computes and the correction applied. The elegant part of the scheme shows up right there: the syndrome, read as a binary number, is exactly the position of the flipped bit. Zero means nothing was corrupted.

The limit is honest and worth knowing: one wrong bit is corrected, two wrong bits are detected as an error but corrected into the wrong word. That is why the extended variant exists, with one more global parity bit, which tells the two cases apart. Hamming shows up in ECC memory, where an isolated cell failure is common and resending is not an option.

Frequently asked questions

Why do the parity bits sit at powers of two?
Because that choice makes the syndrome point straight at the error position. Each parity bit covers the positions whose index has that bit set, so the parity tests, read together as a binary number, spell out the index of the corrupted position — with no lookup table at all.
Does this protect against tampering?
No, and the confusion is common. Hamming corrects noise, not an adversary: someone altering the data deliberately recomputes the parity bits too. Against intentional modification the instrument is a message authentication code or a signature, both of which depend on a key.
What does the code cost?
In this version, three parity bits for four data bits, so nearly half the transmission. The ratio improves a great deal with larger blocks: Hamming (15,11) spends four parity bits on eleven of data, and (31,26) spends five on twenty-six — always correcting one bit per block.

Related Tools