RTL Design #48 · 2026-11-10 · Gray code · Easy · about 10 min

A Gray decoder that only undoes one step

gray_dec is a combinational converter from an 8-bit Gray code back to plain binary. The Gray code of n is n ^ (n >> 1), so gray_dec must return n for that code, for all 256 values.

Run feeds it the Gray codes of 0 to 15 and some of them come back wrong. Fix gray_dec.sv.

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