forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin2gray.sv
35 lines (26 loc) · 836 Bytes
/
bin2gray.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
//------------------------------------------------------------------------------
// bin2gray.sv
// published as part of https://github.com/pConst/basic_verilog
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// Gray code to binary converter
// Combinational design
/* --- INSTANTIATION TEMPLATE BEGIN ---
bin2gray #(
.WIDTH( 32 )
) BG1 (
.bin_in( ),
.gray_out( )
);
--- INSTANTIATION TEMPLATE END ---*/
module bin2gray #( parameter
WIDTH = 32
)(
input [WIDTH-1:0] bin_in,
output logic[WIDTH-1:0] gray_out
);
always_comb begin
gray_out[WIDTH-1:0] = bin_in[WIDTH-1:0] ^ ( bin_in[WIDTH-1:0] >> 1 );
end
endmodule