1. Binary to Gray and back
Build a purely combinational module with two independent 4-bit converters.
The first turns a binary number into its reflected Gray code, the code in which neighbouring values differ in exactly one bit. The second does the reverse: it takes a 4-bit Gray code and returns the binary number it stands for.
There is no clock and no reset. Both outputs follow their inputs immediately.
Ports
| Port | Dir | Bits | What it is |
|---|---|---|---|
bin | in | 4 | Binary number to encode. |
gray_in | in | 4 | Gray code to decode. |
gray_out | out | 4 | The Gray code of bin. |
bin_out | out | 4 | The binary value of gray_in. |
Example
bin = 0110 (6) gives gray_out = 0101. gray_in = 0101 gives bin_out = 0110. Counting 0, 1, 2, 3 in Gray code reads 0000, 0001, 0011, 0010.
Written hints
AI hint
Submissions
No submissions yet. Submit your answer and it shows here. Sign in to keep them.
Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.
Press Build to check your code with Yosys. Errors and warnings show here, and a clean build draws the logic diagram.
Build your design to drive it by hand and see its signals here.