Prev Problem
Next Problem

17. Binary to Gray Code Converter

Back To All Submissions
Previous Submission
Next Submission

Code

/*Write your code here*/

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

assign gray_out = bin_in ^ (bin_in >> 1);
endmodule

this can also be solved in this way 

/*Write your code here*/

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

assign gray_out[3] = bin_in[3];
assign gray_out[2] = bin_in[2] ^ bin_in[3];
assign gray_out[1] = bin_in[1] ^ bin_in[2];
assign gray_out[0] = bin_in[0] ^ bin_in[1];
endmodule
Was this helpful?
Upvote
Downvote