forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gray2bin.sv
39 lines (29 loc) · 915 Bytes
/
gray2bin.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//------------------------------------------------------------------------------
// gray2bin.sv
// published as part of https://github.com/pConst/basic_verilog
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// Binary to gray code converter
// Combinational design
/* --- INSTANTIATION TEMPLATE BEGIN ---
gray2bin #(
.WIDTH( 32 )
) GB1 (
.gray_in( ),
.bin_out( )
);
--- INSTANTIATION TEMPLATE END ---*/
module gray2bin #( parameter
WIDTH = 32
)(
input [WIDTH-1:0] gray_in,
output logic [WIDTH-1:0] bin_out
);
always_comb begin
bin_out[WIDTH-1:0] = '0;
for( integer i=0; i<WIDTH; i++ ) begin
bin_out[WIDTH-1:0] ^= gray_in[WIDTH-1:0] >> i;
end
end
endmodule