RTL Studio Open IDE

Code Conversion

One-Hot→Binary MSB-Priority OR Tree (8→3) — L1 Upgrade

Registered 8-to-3 one-hot to binary encoder with MSB priority and validity check.

About this block

Simulate it in the Verilog IDE

Easyverilogsimsyn

One-Hot→Binary MSB-Priority OR Tree (8→3) — L1 Upgrade is a Verilog reference block in the Code Conversion catalog. Encoders, decoders, priority encoders, and binary/gray converters. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.

This IP core converts an 8-bit one-hot input vector into a 3-bit binary output.

It implements an MSB-priority encoding scheme, where the highest-indexed active bit determines the output value.

The design is fully registered and pipelined to ensure timing closure in high-frequency applications.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for One-Hot→Binary MSB-Priority OR Tree (8→3) — L1 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: Registered 8-to-3 one-hot to binary encoder with MSB priority and validity check.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Features

  • Conversion: 8-bit one-hot to 3-bit binary.
  • Priority: MSB priority (Bit 7 is highest, Bit 0 is lowest).
  • Pipelining: Registered outputs with synchronous reset for improved timing.
  • Validation: Parity-based check to ensure exactly one input bit is set.
  • Logic: Combinational OR-tree for encoding.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low synchronous reset
one_hot_inInput[7:0]8-bit one-hot input vector
binary_outOutput[2:0]3-bit binary encoded output
valid_outOutput1High if exactly one bit in one_hot_in is set

Verification

The included testbench (tb_one_hot_to_binary_8to3_msb_priority_registered_pipelined.v) verifies:

  1. All 8 valid one-hot inputs (bits 0-7).
  2. Two invalid cases: all zeros and multiple bits set.

### Test Case Table

Test CaseInputExpected BinaryExpected ValidResult
TC18'b100000003'b1111'b1PASS
TC28'b000000013'b0001'b1PASS
TC38'b000100003'b1001'b1PASS
TC48'b000010003'b0111'b1PASS
TC58'b010000003'b1101'b1PASS
TC68'b001000003'b1011'b1PASS
TC78'b000001003'b0101'b1PASS
TC88'b000000103'b0011'b1PASS
TC98'b11000000X1'b0PASS
TC108'b00000000X1'b0PASS

### Expected Simulation Results

Run the simulation to see the following log output:

More in Code Conversion

All Code Conversion blocks