HDL code to simulate 4-bit binary to gray converter
Aim- Simulate 4-bit binary to gray converter using HDL code.
Basics of 4-bit binary to gray converter
what is gray code?
A Gray Code represents binary encoded number constitutes a sequence of bits such that only one bit in the group changes from before and after.
To convert Binary to converter,
G3=B3, G2=B3^B2, G1=B2^B1, G0=B1^B0
HDL Program to simulate 4-bit binary to gray converter
Verilog Code module bitogr( input [3:0] b, output [3:0] g); assign g=b; assign g=b^b; assign g=b^b; assign g=b^b; endmodule
Verilog Test Bench module bitogr_tb; reg [3:0] b; wire [3:0] g; bitogr uut (.b(b), .g(g) ); initial begin b=0; #100; b=1; #100; b=2; #100; b=3; #100; b=4; #100; b=5; #100; b=6; #100; b=7; #100; b=8; #100; b=9; #100; b=10; #100; b=11; #100; b=12; #100; b=13; #100; b=14; #100; b=15; #100; endmodule