Binary to Gray Conversion

AMD

Problem Description

πŸš€ Design Challenge: The Universal Gray Encoder

In high-speed digital design, transitions are dangerous. When multiple bits of a binary counter flip simultaneously (like 0111 to 1000), hardware can misread intermediate states. The solution? Gray Code.

The Specification

Your task is to design a parameterized module that converts an $N$-bit binary input into its corresponding Gray code equivalent.

Gray Encoder

Decimal

Binary Input

Gray Code Output

0

0000

0000

1

0001

0001

2

0010

0011

3

0011

0010

4

0100

0110

5

0101

0111

6

0110

0101

7

0111

0100

8

1000

1100

9

1001

1101

10

1010

1111

11

1011

1110

12

1100

1010

13

1101

1011

14

1110

1001

15

1111

1000

Below is the parameters :

Feature

Description

Parameter: WIDTH

The bit-width of the converter (Default = 4)

Input: bin_in

The N-bit binary value to convert

Output: gray_out

The resulting N-bit Gray code

Verilog

Code Editor Access

Log in to write, run and submit your solution to this interview question. It's free.

Output

Output goes here...