SECTION 03 / 5

Encoders and Priority Encoders

3 min read
On this page 5 headings

Start here A decoder turns a code into “one line on”. An encoder does the opposite: it sees which line is on and gives back its number in binary. Think of a quiz-show buzzer panel: the player whose buzzer is pressed gets their seat number shown on the screen.

The encoder

  • 2ⁿ inputs → n outputs.
  • It assumes exactly one input is 1 at a time, and outputs that input’s number in binary.
Decoder: code → one line on. Encoder: one line on → code.
Decoder: code → one line on. Encoder: one line on → code.
Open image ↗
Encoder is the opposite of a decoder

The 4-to-2 encoder

I3I_{3} I2I_{2} I1I_{1} I0I_{0} Y1Y_{1} Y0Y_{0}
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1

Equations: Y1=I2+I3Y_{1} = I_{2} + I_{3} and Y0=I1+I3Y_{0} = I_{1} + I_{3}.

Why? Y1Y_{1} is the “2s” bit. It is 1 for inputs 2 and 3. Y0Y_{0} is the “1s” bit. It is 1 for inputs 1 and 3.

The problem: what if two inputs are 1 together, like I1I_{1} and I2I_{2}? Then Y1=1Y_{1} = 1 and Y0=1→Y_{0} = 1 \to output 11 = 3, which is wrong! Neither 1 nor 2 was chosen.

The priority encoder

A priority encoder fixes this: if many inputs are 1, the highest-numbered input wins. The lower ones are ignored.

Three vehicles arrive together, but the ambulance (highest priority) goes first. The lower ones must wait.
Three vehicles arrive together, but the ambulance (highest priority) goes first. The lower ones must wait.
Open image ↗
Priority: the highest wins

The 4-to-2 priority encoder

I3I_{3} I2I_{2} I1I_{1} I0I_{0} Y1Y_{1} Y0Y_{0} Winner
1 X X X 1 1 3
0 1 X X 1 0 2
0 0 1 X 0 1 1
0 0 0 1 0 0 0

X=X = “don’t care”: it doesn’t matter whether that input is 0 or 1, because a higher input has already won.

Read the table from the top. The first 1 you meet (the highest input) decides the output.
Read the table from the top. The first 1 you meet (the highest input) decides the output.
Open image ↗
Priority encoder truth table

Equations:

  • Y1=I3+I2Y_{1} = I_{3} + I_{2} (the winner is 2 or 3)
  • Y0=I3+I2‾⋅I1Y_{0} = I_{3} + \overline{I_{2}} \cdot I_{1} (the winner is 3, or it’s 1 and input 2 is not on)

Why the I2‾\overline{I_{2}} in Y0Y_{0}? IfI2I f I_{2} is on, input 2 wins, and 2 = 10 has Y0=Y_{0} = 0. So I1I_{1} can only set Y0Y_{0} when I2I_{2} is off.

Worked example (2026 T2 end-term, answer 10) Inputs (L3,L2,L1,L0)=(0,1,1,1)\left(L_{3} , L_{2} , L_{1} , L_{0}\right) = \left(0 , 1 , 1 , 1\right), with Y1=L3+L2Y_{1} = L_{3} + L_{2} and Y0=L3+L2‾L1Y_{0} = L_{3} + \overline{L_{2}} L_{1}.

  • Y1=0+1=Y_{1} = 0 + 1 = 1
  • Y0=0+(0⋅1)=Y_{0} = 0 + \left(0 \cdot 1\right) = 0 (L2=1L_{2} = 1, so L2‾=0\overline{L_{2}} = 0)
  • Output = 10 (input 2 wins, as it’s the highest one that is on) ✔

Everyday example: an ambulance, a bus and a car all reach a junction at the same time. The traffic police let the ambulance go first. It has the highest priority.

In one line: An encoder turns “one line on” into its binary number (2n→n)\left(2^{n} \to n\right); a priority encoder lets the highest active input win when several are on. Exam words: encoder, 4-to-2 encoder, priority encoder, highest priority, don’t care (X).


Quick check

How many outputs does an 8-to-3 encoder have? 3 (2³ = 8 inputs).
4-to-2 priority encoder, inputs I3I2I1I0=0011I_{3} I_{2} I_{1} I_{0} = 0 0 1 1. Output? 01 (input 1 is the highest one that is on).
Plain 4-to-2 encoder (no priority), inputs I2I_{2} and I1I_{1} both on. What goes wrong? It outputs 11 (= 3), which is neither of the active inputs.
YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑