Codiode

Binary to Gray Code Datapath

EasyVerilog / SystemVerilogBuildFree33 solved

Binary to Gray is the step before a pointer crosses a clock boundary: each output bit is the XOR of two neighbouring input bits.

The module takes an N-bit binary input and computes the corresponding N-bit Gray code output. The most significant bit (MSB) of the Gray code is identical to the MSB of the binary input. Each subsequent bit is the XOR of the current binary bit and the next higher binary bit. This ensures that any two consecutive numerical values will differ by only a single bit in their Gray code representation.

This is a purely combinational circuit. There is no clock or reset, and the output reflects the input immediately.

Signal Direction Width Description
bin input WIDTH Binary input value
gray output WIDTH Gray code output value

Constraints

  • The module must be purely combinational.
  • Output gray must reflect changes in bin immediately with 0-delay.
  • The design must support a parameterised WIDTH, defaulting to 4.
  • The testbench will instantiate the module with WIDTH overridden to 8.

Topics

CDCCombinational LogicDatapath

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

Free to solve. A Codiode account keeps your progress.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Combinational RTL

Problem 8 of 15 in the Combinational RTL track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.