Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ640
Q640DesignArchASIC interview problem

Implement a parameterized binary-to-Gray converter

TechniquesDesignSystemVerilogGray codeCombinational logic
DifficultyEasy
TopicRTL Design
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

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

Module declarationSystemVerilog
module bin_to_gray #(
  parameter int W = 4
) (
  input  logic [W-1:0] bin,
  output logic [W-1:0] gray
);

Example input and output

Use this case to check your interpretation
Input
W=4, bin=4'b1010
Output
gray=4'b1111
Explanation

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

02

Requirements (4)

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