Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Implement a parameterized binary-to-Gray converter

Hardware interview practice

Implement a parameterized binary-to-Gray converter

EasyRTL DesignSystemVerilog

Write a synthesizable, parameterized combinational block that converts a binary pointer to Gray code without changing bit order.

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_gray #(
  parameter int W = 4
) (
  input  logic [W-1:0] bin,
  output logic [W-1:0] gray
);
Reviewed example

Work through one case

Input
W=4, bin=4'b1010
Expected output
gray=4'b1111

Shifting 1010 right produces 0101, and 1010 XOR 0101 equals 1111.

What to cover

Requirements

  1. Use one combinational relation with no state.
  2. Support every legal parameter value W >= 1.
  3. Preserve the declared bit order.
  4. State the exact binary-to-Gray relation.
Continue practicing

Related questions

RTL DesignReverse a physical bus at the lane boundary→RTL DesignDiagnose storage from an incomplete always_comb block→RTL DesignChoose always_comb over a manual sensitivity list→
asic.fyi · Learn silicon end to end.info@asic.fyi