Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ400
Page ↗
Q400DesignDVAppleASIC interview problem

Binary-to-Gray converter

TechniquesDesignDVGray codeAsync FIFO
DifficultyEasy
TopicClock Domain Crossing
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Write combinational SystemVerilog that converts an 8-bit binary value to reflected Gray code and reconstructs the original binary value.

Module declarationSystemVerilog
module gray8 (
  input  logic [7:0] bin,
  output logic [7:0] gray,
  output logic [7:0] bin_back
);

Example input and output

Use this case to check your interpretation
Input
bin=8'd7
Output
gray=8'd4, bin_back=8'd7
Explanation

Binary 0000_0111 converts to Gray 0000_0100 and the prefix XOR reconstructs the input.

02

Requirements (4)

  • Use gray = bin ^ (bin >> 1) for forward conversion.
  • Copy the Gray MSB and prefix-XOR downward for reverse conversion.
  • Keep both conversions purely combinational.
  • Bound the reverse loop with a signed int index to avoid unsigned underflow.