Code Conversion
8-Bit Thermometer to Binary Encoder
Combinational priority encoder converting 8-bit thermometer code to 3-bit binary index with MSB priority.
About this block
Simulate it in the Verilog IDE
8-Bit Thermometer to Binary Encoder 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 implements an 8-bit thermometer-to-binary encoder. It converts an 8-bit one-hot (thermometer) input code into a 3-bit binary index representing the position of the highest set bit (MSB priority). The module is purely combinational, ensuring low latency, and includes a valid signal to indicate when the input is non-zero. It is fully verified with a comprehensive testbench covering all critical edge cases.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Thermometer to Binary Encoder.
- Read the Verilog module in the editor. The catalog line for this block: Combinational priority encoder converting 8-bit thermometer code to 3-bit binary index with MSB priority.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- 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
- Functionality: Converts 8-bit thermometer code to 3-bit binary index.
- Priority: MSB priority (highest index wins).
- Latency: Combinational logic for minimal delay.
- Verification: Includes a testbench with 8 distinct test cases covering all zeros, single bits, multiple bits, and all bits set.
- Simulation: Verified using Icarus Verilog.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
thermo_in | Input | 8 | 8-bit thermometer code input. |
bin_out | Output | 3 | Binary index of the highest set bit in thermo_in. |
valid | Output | 1 | High (1) when any bit in thermo_in is high. Low (0) if all inputs are zero. |
Verification
The testbench tb_thermometer_to_binary_8b.v verifies the following scenarios:
| Test Case | Description | Expected bin_out | Expected valid | Status |
|---|---|---|---|---|
| TC1 | All zeros input | 3'b000 | 0 | PASS |
| TC2 | LSB set (index 0) | 3'b000 | 1 | PASS |
| TC3 | MSB set (index 7) | 3'b111 | 1 | PASS |
| TC4 | Middle bit set (index 3) | 3'b011 | 1 | PASS |
| TC5 | Multiple bits set (MSB priority) | 3'b110 | 1 | PASS |
| TC6 | All bits set | 3'b111 | 1 | PASS |
| TC7 | Single bit at index 4 | 3'b100 | 1 | PASS |
| TC8 | Single bit at index 6 | 3'b110 | 1 | PASS |
All 8 test cases passed successfully.
More in Code Conversion
- 16-Bit Priority Encoder — L1 Upgrade — L2 Upgrade
- 4-Bit BCD to Binary Converter — L2 Upgrade
- 4-Bit Binary to BCD Converter (Shift-and-Add-3)
- 4-Bit Thermometer to Binary Encoder
- 8-Bit One-Hot Encoder
- 8-Bit Priority Decoder (One-Hot to Binary) — L1 Upgrade — L2 Upgrade
- 8-Bit to 16-Bit Sign Extender
- 8-to-16 Zero Extension — L1 Upgrade
- Binary to Excess-3 4-bit — L1 Upgrade — L2 Upgrade
- Binary→Thermometer Compare-Gen (8→9)
- Binary→Thermometer LUT (4→15, Case) — L1 Upgrade — L2 Upgrade
- Gray-Code Incrementer 8-Bit
- N-Bit Gray to Binary Decoder
- N-bit Priority Encoder — L1 Upgrade — L2 Upgrade
- One-Hot→Binary Case Decode (4→2) — L1 Upgrade — L2 Upgrade
- One-Hot→Binary MSB-Priority OR Tree (8→3) — L1 Upgrade