1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00
oh/common/hdl/oh_bin2onehot.v
Andreas.Olofsson 6d1735d3b9 Fixing a bunch of synthesis issues
-Better to fix to avoid issues across different synthesis platform
(even if standard would allow if for verilog2005)
2020-08-17 16:11:42 -04:00

28 lines
879 B
Verilog

//#############################################################################
//# Function: Binary to one hot encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_bin2onehot #(parameter N = 2, // output vector width
parameter NB = $clog2(N) // binary encoded input
)
(
input [NB-1:0] in, // unsigned binary input
output [N-1:0] out // one hot output vector
);
genvar i;
for(i=0;i<N;i=i+1) begin: gen_onehot
assign out[i] = (in[NB-1:0] == i);
end
endmodule // oh_bin2onehot