Binary to Gray Code Converter - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

202


14
 
1
//vlsiverify.com
2
module TB;
3
  reg [3:0] binary, gray;
4
  b2g_converter b2g(binary, gray);
5
  
6
  initial begin
7
    $monitor("Binary = %b --> Gray = %b", binary, gray);
8
    binary = 4'b1011; #1;
9
    binary = 4'b0111; #1;
10
    binary = 4'b0101; #1;
11
    binary = 4'b1100; #1;
12
    binary = 4'b1111;
13
  end
14
endmodule
xxxxxxxxxx
1
10
 
1
module b2g_converter #(parameter WIDTH=4) (input [WIDTH-1:0] binary, output [WIDTH-1:0] gray);
2
  genvar i;    
3
  generate
4
    for(i=0;i<WIDTH-1;i++) begin
5
      assign gray[i] = binary[i] ^ binary[i+1];
6
    end
7
  endgenerate
8
  
9
  assign gray[WIDTH-1] = binary[WIDTH-1];
10
endmodule
1670 views and 1 likes     
 
Binary to Gray Code Converter implementation in Verilog

Binary to Gray Code Converter implementation in Verilog

180:0