Prev Problem
Next Problem

17. Binary to Gray Code Converter

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

MSB of the Gray output is identical to the MSB of the binary input. Each subsequent Gray bit is obtained by performing a bitwise XOR between the corresponding binary bit and its immediate higher-order binary bit.

 

Code

module bin2gray4(
    input [3:0] bin_in,
    output [3:0] gray_out
);

    assign gray_out = {bin_in[3],bin_in[3]^bin_in[2],bin_in[2]^bin_in[1],bin_in[1]^bin_in[0]};

endmodule
Was this helpful?
Upvote
Downvote