We can use the left shift operator to XOR the binary number with the left shifted version of itself and obtain the gray 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