mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-30 02:32:53 +08:00
62469afc4b
Using parameter instead works. Signed-off-by: Ola Jeppsson <ola@adapteva.com>
29 lines
865 B
Verilog
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
|
|
|
|
|
|
|
|
|
|
|