Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Write an eight-bit binary-to-Gray converter

Hardware interview practice

Write an eight-bit binary-to-Gray converter

EasyMemory SystemsSystemVerilog

An asynchronous-FIFO pointer helper needs reflected Gray code with zero latency. Write the combinational converter.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

module bin_to_gray8(
  input logic [7:0] bin, output logic [7:0] gray
);
Reviewed example

Work through one case

Input
Case 1: bin=8'h00
Case 2: bin=8'h0B
Case 3: bin=8'hFF
Expected output
Case 1: Produces gray=8'h00.
Case 2: Produces gray=8'h0E.
Case 3: Produces gray=8'h80.

The shown result follows by applying this rule: A single XOR of the input with its one-bit logical right shift implements the converter. The cases also demonstrate this requirement: For consecutive two-state binary counts, the two Gray outputs must differ in exactly one bit, including 8'hFF to 8'h00 wraparound.

What to cover

Requirements

  1. Implement reflected Gray conversion as gray = bin ^ (bin >> 1).
  2. Use purely combinational logic with no clock, reset, latch, or retained state.
  3. Preserve all eight bits, including the most-significant bit and leading zeros.
  4. For consecutive two-state binary counts, the two Gray outputs must differ in exactly one bit, including 8'hFF to 8'h00 wraparound.
Continue practicing

Related questions

Memory SystemsSize a Width-Converting Asynchronous FIFO→RTL DesignBuild a synchronous FIFO and race-free BFM→Clock Domain CrossingGenerate and synchronize a Gray-code counter→
asic.fyi · Learn silicon end to end.info@asic.fyi