CBL_BinaryToOneHot : A combinational logic converting a binary code to a one-hot code
This model describes a combinational logic converting an N-bit binary code to a (2^N)-bit one-hot code. For example, the model converts a 3-bit binary-coded input to an 8-bit one-hot-coded output following the patterns below.
3'b000 --> 8'b00000001 3'b001 --> 8'b00000010 3'b010 --> 8'b00000100 3'b011 --> 8'b00001000 3'b100 --> 8'b00010000 3'b101 --> 8'b00100000 3'b110 --> 8'b01000000 3'b111 --> 8'b10000000
module CBL_BinaryToOneHot #( parameter width = 4 // bit width of the binary-coded input )( input [width-1:0] in, // binary-coded input output reg [(1<<width)-1:0] out // one-hot-coded output ); int i; always @(in) begin for (i=0; i<(1<<width); i=i+1) begin out[i] = (in == i) ? 1 : 0; end end endmodule
Input/Output Terminals
Name | I/O | Type | Description |
in [width-1:0] | input | wire | binary-coded input |
out [(1<<width)-1:0] | output | reg | one-hot-coded output |
Parameters
Name | Type | Default | Description |
width | integer | 4 | bit width of the binary-coded input |
List of Testbenches
tb_check : A testbench for checking the basic functionality of a combinational logic |
tb_check : A testbench for checking the basic functionality of a combinational logic
This testbench checks the basic functionality of a combinational logic by enumerating all the possible input values and listing its corresponding outputs.
module tb_check (); parameter in_width = 4; parameter out_width = (1 << in_width); reg [in_width-1:0] in; wire [out_width-1:0] out; CBL_BinaryToOneHot #(.width(in_width)) DUT (.in, .out); initial begin in = 0; repeat ((1 << in_width) - 1) begin #(1ns); in = in + 1; end end always @(out) begin $display("IN: %b --> OUT: %b", in, out); end endmodule