RTL Design #40 · 2026-11-02 · ECC · Medium · about 15 min

Hamming(7,4) decoder

hamming74_dec decodes a 7-bit Hamming(7,4) codeword. code[0] is codeword position 1 and code[6] is position 7. Positions 1, 2 and 4 hold parity bits, and positions 3, 5, 6 and 7 hold data bits d0..d3.

The three parity checks (the syndrome) read as a number equal to the position of a single flipped bit, or 0 if there is none. The decoder flips that bit, outputs the four corrected data bits and raises corrected when the syndrome was not 0.

Clean codewords decode fine, but data comes out wrong when a bit has been flipped. Fix hamming.sv.

Write and run your answer in the browser. The hidden tests check it, and it’s free.