Prev Problem
Next Problem

17. Binary to Gray Code Converter

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

We can use the left shift operator to XOR the binary number with the left shifted version of itself and obtain the gray code.

 

 

Code

/*Write your code here*/
module bin2gray4 (input [3:0] bin_in, output [3:0] gray_out);
    wire [3:0] w1;
    assign w1 = (bin_in>>1'd1);
    assign gray_out = bin_in^w1;
endmodule
Was this helpful?
Upvote
Downvote