Hardware interview practice
Implement a parameterized binary-to-Gray converter
Write a synthesizable, parameterized combinational block that converts a binary pointer to Gray code without changing bit order.
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'b1010Expected output
gray=4'b1111Shifting 1010 right produces 0101, and 1010 XOR 0101 equals 1111.
What to cover
Requirements
- 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.
