Hamming(7,4) Encoder/Decoder

Add error-detecting parity bits using Hamming code

Ad placeholder (leaderboard)

What this tool does

This tool implements the classic Hamming(7,4) error-correcting code. Encoding takes 4 data bits and adds 3 parity bits to form a 7-bit codeword that can survive a single-bit flip. Decoding takes a (possibly corrupted) 7-bit codeword, computes a syndrome, corrects one bit if needed, and recovers the original 4 data bits.

How it works

The 7 positions are numbered 1–7. Positions that are powers of two — 1, 2 and 4 — hold the parity bits p1, p2, p4; the remaining positions 3, 5, 6, 7 hold the data bits.

Each parity bit covers the positions whose index includes its bit:

p1 (pos 1) covers positions 1, 3, 5, 7
p2 (pos 2) covers positions 2, 3, 6, 7
p4 (pos 4) covers positions 4, 5, 6, 7

Each parity bit is chosen so the sum of the bits it covers is even (even parity).

Decoding recomputes the three parity checks over the received word. The check results, written as c4 c2 c1, form a syndrome. If the syndrome is 000, no single-bit error is detected. Any other value is the position number of the corrupted bit — so a syndrome of 101 (= 5) means position 5 was flipped, and the decoder flips it back before extracting the data.

Example

Data 1011 (d1=1 d2=0 d3=1 d4=1). The encoder produces parity bits and lays out the codeword as p1 p2 d1 p4 d2 d3 d4. Flip any one of those 7 bits and the decoder’s syndrome will name the exact position to repair.

Notes

  • Input must be exactly 4 bits to encode or exactly 7 bits to decode; the tool validates length and character set.
  • The decoder reports the syndrome and the corrected position so you can see the mechanism, not just the answer.
Ad placeholder (rectangle)