3.3.7 · D2Combinational Circuits

Visual walkthrough — Encoders and priority encoders

1,916 words9 min readBack to topic

Step 1 — What are the wires? (the one-hot picture)

WHAT. We have four input wires named . Each wire is either HIGH (carrying a 1, "on") or LOW (carrying a 0, "off"). We have two output wires and .

WHY start here. Before any algebra, you must see what a signal is: a wire is just a road that is either lit or dark. The word one-hot means "exactly one wire is lit at a time" — like a row of light bulbs where only one glows.

PICTURE. Four bulbs in a row. Only glows (red). The job of the box is to shout its number — the label — on the output wires.

Figure — Encoders and priority encoders

Step 2 — Turn the wanted behaviour into a table

WHAT. List every "which wire is lit" case and the binary number we want out. This list is called a truth table — it just records, row by row, "given these inputs, what output do we demand?"

WHY. We cannot design a circuit until we have pinned down its goal exactly. The table is the goal, frozen. Nothing is derived yet; we are only writing our wish.

Lit wire its index
0 0 0
1 0 1
2 1 0
3 1 1

PICTURE. The same four bulbs, but now each row is drawn with its wanted two-bit answer glued to the right. Notice the pattern in the coloured column.

Figure — Encoders and priority encoders

Step 3 — Read each output column down the table

WHAT. Instead of reading the table left-to-right (per row), read it top-to-bottom, one output column at a time. Ask: "For which lit wires is this column a 1?"

WHY. Each output bit is a separate little machine. If I know exactly which inputs must switch a bit ON, I can wire that bit directly — I do not need to think about the other bit at all. Splitting the problem this way is the whole trick.

Reading the column down: it is for and (the odd indices — the ones whose binary form ends in 1). Reading the column down: it is for and (the indices — whose binary form starts with 1).

PICTURE. The table with two coloured highlight bands: the -band touches rows ; the -band touches rows .

Figure — Encoders and priority encoders

Step 4 — Wire it with OR gates (the plain encoder)

WHAT. " is 1 when is lit or is lit" is exactly what an OR gate does: an OR gate outputs 1 if any of its inputs is 1.

WHY OR and not AND? We want "either of these fires it." AND would demand both at once — but our rule is one-hot, only one wire is ever lit, so "both" never happens and AND would output 0 forever. OR is the tool that matches the word "or" in our reading of Step 3.

PICTURE. Two OR gates. Wire and feed the top gate (); and feed the bottom gate (). The shared wire (red) fans out to both.

Figure — Encoders and priority encoders

Step 5 — Watch it break: two wires lit at once

WHAT. Feed in and together. Trace the OR gates: Output .

WHY it's wrong. We lit wires 1 and 2, but the box shouted 3 — a number we never pressed! The OR gates each did their honest local job, but they merged the bit from index 1 into the bit from index 2, manufacturing a code belonging to neither.

PICTURE. Both and glowing; the red arrows show bit-from-1 and bit-from-2 colliding at the output to make the fake "3".

Figure — Encoders and priority encoders

Step 6 — Fix #1: the Valid bit

WHAT. Add one more output, , that is 1 iff at least one input is lit:

WHY. This cures failure #2. When nothing is pressed, every , so — a flag saying "ignore the wires, the room is empty." When alone is pressed, and genuinely means index 0. The ambiguity is gone: with = nothing; with = index 0.

PICTURE. A single big OR gate eating all four inputs and lighting the lamp; a side panel contrasts " = empty" vs " = bell 0".

Figure — Encoders and priority encoders

Step 7 — Fix #2: install priority (the tie-breaker)

WHAT. Choose a ranking: . Rule: when several are lit, report the highest-ranked one and ignore the rest. The below means don't-care (this input may be 0 or 1, it doesn't change the answer because a higher input already decided it).

0 0 0 0 0
0 0 0 1 0 0 1
0 0 1 0 1 1
0 1 1 0 1
1 1 1 1

WHY. The columns are the visible proof of priority: once , we don't care what do — the winner is locked. This deterministic rule replaces the garbage of Step 5.

PICTURE. A staircase: from the top row down, the "already decided" cells collapse into don't-cares. The lit winner in each row is red.

Figure — Encoders and priority encoders

Step 8 — Derive the priority equations, term by term

WHAT & WHY, bit by bit.

must be 1 for indices 2 and 3. Both winners ( alone, or ) demand , and outranking still gives — so no suppression is needed:

must be 1 for indices 1 and 3. But is dangerous: if (a higher rank) is also lit, index 2 wins and demands . So may only speak when is silent. We gate it with ("NOT ", meaning is off): Here writing two symbols side by side, , means AND: both must be true — lit and dark.

Why does not need a guard? Nothing outranks , and index 3 is odd so it wants anyway — it can never be wrong.

PICTURE. The gate redrawn: passes through an AND with the inverted (a bubble on the wire = NOT), then ORs with . The red bubble is the whole idea.

Figure — Encoders and priority encoders

Step 9 — Re-run the broken case (does the fix hold?)

WHAT. Same trouble input as Step 5: , others 0. Now through the priority equations:

  • — someone's here.
  • .
  • .
  • Output . ✅

WHY it now works. outranks ; the bubble switched OFF 's contribution, so index 2 (the higher wire) cleanly wins. The garbage "3" is impossible.

PICTURE. Side-by-side: left = plain encoder shouting the fake "3"; right = priority encoder shouting the correct "2", with the bubble crossing out 's influence (red).

Figure — Encoders and priority encoders

The one-picture summary

Everything compressed: four inputs → an OR-net (plain encoder) → break under collisions → add (validity) and suppression (priority) → clean binary code out.

Figure — Encoders and priority encoders
Recall Feynman: the whole walkthrough in plain words

Picture four doorbells, numbered 0 to 3, and a little box that must shout the number of whichever bell rang, using just two on/off wires (binary). We first read our wish as a table, then noticed each output wire is simply an OR — "light this bit if bell 1 or bell 3 rang." That's the plain encoder. But two kids can ring at once. The plain box merges their bits and shouts a bell nobody pressed. Two fixes: (1) a Valid lamp that only glows when someone actually rang — so "0-0 and dark" means empty, "0-0 and lit" means bell 0; and (2) a politeness rule — always report the biggest bell, silencing smaller ones. In wiring, that silencing is a little NOT bubble: bell 1 only gets a voice when bell 2 is quiet. Re-run the two-kid case and the box now correctly names the bigger bell. Done.


Connections

  • Decoders — run this whole picture backwards.
  • Multiplexers — same OR-of-selected-lines flavour.
  • Interrupt controllers — where the priority rule earns its keep.
  • Boolean algebra simplification — why is the minimal guard.
  • Karnaugh maps — the don't-cares of Step 7 fill K-map cells.
  • Combinational circuits — parent family; no memory, output = pure function of inputs.