1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00
oh/src/common/hdl/oh_bin2onehot.v
Ola Jeppsson 62469afc4b Vivado doesn't like localparam / clog2 combo
Using parameter instead works.

Signed-off-by: Ola Jeppsson <ola@adapteva.com>
2016-04-14 21:46:14 +02:00

29 lines
865 B
Verilog

//#############################################################################
//# Function: Binary to one hot encoder #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_bin2onehot #(parameter DW = 32) // width of data inputs
(
input [NB-1:0] in, // unsigned binary input
output [DW-1:0] out // one hot output vector
);
parameter NB = $clog2(DW); // encoded bit width
integer i;
reg [DW-1:0] out;
always @*
for(i=0;i<DW;i=i+1)
out[i]=(in[NB-1:0]==i);
endmodule // oh_bin2onehot