CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Arithmetic

Gray Code to Binary Datapath

MediumVerilog / SystemVerilogBuild

Clock domain crossing (CDC) circuits, such as asynchronous FIFOs, rely on Gray code to safely transfer multi-bit pointers across asynchronous boundaries. Once safely synchronized into the receiving clock domain, these Gray code pointers must be converted back to standard binary format to calculate FIFO occupancy and evaluate full/empty conditions.

The datapath module performs a purely combinational conversion from a parameterized Gray code input to a standard binary output. In Gray code to binary conversion, the most significant bit (MSB) of the binary output is identical to the MSB of the Gray code input. Each subsequent binary bit is the XOR of the corresponding Gray code bit and the previously calculated binary bit (the one at the next higher index).

Because this conversion sits in the critical timing path of a FIFO controller, it must be evaluated combinationally without requiring additional clock cycles.

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | gray_in | input | WIDTH | Gray code input value | | bin_out | output | WIDTH | Binary converted output value |

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | WIDTH | integer | 8 | Bit width of the input and output buses |

Constraints

  • The module must be completely combinational; do not include clock or reset ports.
  • The design must support any WIDTH strictly greater than 1.
  • The output bin_out must update combinationally immediately when gray_in changes.

Topics

ParameterizedCDCCombinational LogicDatapath

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Binary to Gray Code DatapathEasy
  • Fixed Point Multiplication with SaturationHard
  • Absolute Value with Bit GrowthMedium
  • 8 bit Basic ALU with FlagsEasy
  • 8-bit Combinational PopcountMedium
  • 8-bit Logical Barrel ShifterMedium
  • 16-bit Arithmetic Barrel ShifterHard
  • Parameterized ALU with Safe DefaultsMedium

Browse all problems · Learning tracks