`timescale 1ns/1ps module binary_to_grey(grey, binary); output [3:0] grey; input [3:0] binary; buf(grey[3], xor(grey[2], xor(grey[1], xor(grey[0],
binary[3]); binary[3], binary[2]); binary[2], binary[1]); binary[1], binary[0]);
endmodule `timescale 1ns/1ps module binary_to_grey_tb; reg [3:0] binary_input; wire [3:0] grey_output; binary_to_grey DUT(grey_output, binary_input); initial begin #50 #50 #50 #50
binary_input= binary_input= binary_input= binary_input=
4'b1011; 4'b1010; 4'b0110; 4'b1000;
$monitor($time, "binary_input=%b, grey_output=%b", binary_input, grey_output); end endmodule