-
Notifications
You must be signed in to change notification settings - Fork 383
/
bin2pos.sv
executable file
·39 lines (29 loc) · 921 Bytes
/
bin2pos.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
//------------------------------------------------------------------------------
// bin2pos.sv
// Konstantin Pavlov, pavlovconst@gmail.com
//------------------------------------------------------------------------------
// INFO ------------------------------------------------------------------------
// Converts binary coded value to positional code (one-hot in specified position)
// Thus 2'd0 becomes 4'b0001 and 8'd5 becomes 256'b100000
// Module is being synthesized into combinational logic only
// See also pos2bin.sv module for inverse transformation
/* --- INSTANTIATION TEMPLATE BEGIN ---
bin2pos #(
.BIN_WIDTH( 8 )
) BP1 (
.bin( ),
.pos( )
);
--- INSTANTIATION TEMPLATE END ---*/
module bin2pos #( parameter
BIN_WIDTH = 8,
POS_WIDTH = 2**BIN_WIDTH
)(
input [(BIN_WIDTH-1):0] bin,
output logic [(POS_WIDTH-1):0] pos
);
always_comb begin
pos = 0;
pos[bin] = 1'b1;
end
endmodule