
Encoders
The reverse of a decoder: turns one active line into its binary code.
Description
A circuit that outputs the binary code of an asserted input line. It compresses many status lines into a compact code (e.g. interrupts). OR-combine input indices; a priority encoder picks the highest active line.
- A plain encoder assumes exactly one input is active.
- A priority encoder handles multiple actives by choosing the highest.
- A 'valid' output flags whether any input is active at all.
- What: A circuit that outputs the binary code of an asserted input line.
- Why: It compresses many status lines into a compact code (e.g. interrupts).
- How: OR-combine input indices; a priority encoder picks the highest active line.
- Where: Interrupt controllers, keypad scanning, position encoding.
- When: When one of many events must be reported as a number.
- O1 = I2 + I3
- O0 = I1 + I3
At a glance
What
A circuit that outputs the binary code of an asserted input line.
Why
It compresses many status lines into a compact code (e.g. interrupts).
How
OR-combine input indices; a priority encoder picks the highest active line.
Where
Interrupt controllers, keypad scanning, position encoding.
When
When one of many events must be reported as a number.
Think of it like…
The reverse of the buzzer panel: a doorbell rings and the system tells you which flat number it was. If several ring at once, a priority encoder reports the most important one.
Priority encoding
- A plain encoder assumes exactly one input is active.
- A priority encoder handles multiple actives by choosing the highest.
- A 'valid' output flags whether any input is active at all.
4-to-2 priority encoder (highest wins)
| Active input | Output | Valid |
|---|---|---|
| none | 00 | 0 |
| I0 | 00 | 1 |
| I1 | 01 | 1 |
| I2 | 10 | 1 |
| I3 | 11 | 1 |
Black-box view
Inputs on the left → outputs on the right · particles show signal direction
Logic diagram
Click inputs to toggle · glowing wires carry 1 · particles show signal direction
The 5 Whys
- 1
Why an encoder? To compress many lines into a small code.
- 2
Why compress? Buses and registers carry codes, not one-hot lines.
- 3
Why priority? Two inputs may assert at once and must be resolved.
- 4
Why a valid bit? Code 00 is ambiguous between 'I0' and 'none'.
- 5
Root cause: encoding is the inverse mapping that packs selections back into numbers.
Cheat sheet
Working principle
- OR-combine input indices; a priority encoder picks the highest active line.
- A circuit that outputs the binary code of an asserted input line.
Formulas & Boolean expressions
- O1 = I2 + I3
- O0 = I1 + I3
Key facts
- A plain encoder assumes exactly one input is active.
Why it exists
- Root cause: encoding is the inverse mapping that packs selections back into numbers.