3.3.7 · D4Combinational Circuits

Exercises — Encoders and priority encoders

2,770 words13 min readBack to topic

Quick reminders of the tools we will lean on (from the parent):

  • A -to- encoder: inputs , outputs. When one input is HIGH it outputs that input's binary index.
  • Plain 4-to-2: , .
  • Priority 4-to-2: , , .
  • Notation: means OR, juxtaposition () means AND, means NOT .

Level 1 — Recognition

Recall Solution L1-Q1

WHAT: many lines in (8 buttons), one number out (3 bits). That is compression position → number, which is exactly the encoder direction. A decoder goes the other way (). Answer: an 8-to-3 encoder inputs, outputs. Check: output wires. ✅

Recall Solution L1-Q2

Use the equations. . . Answer: . That is index 3 — correct, because is the active line. ✅


Level 2 — Application

Recall Solution L2-Q1

WHY this rule: is the "value-4" column of the 3-bit index. It must be 1 exactly when the index has its bit-2 set, i.e. . Look at the figure: the indices whose bit-2 is 1 are grouped on the right.

Figure — Encoders and priority encoders

Answer: . (For completeness: , .)

Recall Solution L2-Q2

(something is on). . . Answer: , . Correct index. ✅

Recall Solution L2-Q3

WHAT: two inputs on — the priority rule ("highest index wins") must pick . . . . Answer: , . (highest) wins, is ignored. ✅


Level 3 — Analysis

Recall Solution L3-Q1

WHY it can be ambiguous: the plain encoder OR-s bits from whichever inputs are on; it has no way to know only one is on. Try and : , . So and both give . Answer: active also yields . The output therefore does not uniquely mean "." A plain encoder is only trustworthy when the one-hot guarantee holds. ✅

Recall Solution L3-Q2

WHAT happens: the output is the bitwise OR of the two indices, not either index itself. With and active: , . Here it accidentally equals index 1. But take and : OR , which is neither. General reason: equals or only when one index's set bits are a subset of the other's. Otherwise you get a third code. Answer: the merged output is the bitwise OR of the two indices; it matches a real input only in the special subset case, so in general it is garbage — which is exactly why priority encoders exist. ✅

Recall Solution L3-Q3

WHY: a suppression term is only needed when a higher-priority input wants that output bit cleared while a lower one wants it set.

  • Indices whose bit-1 is set: . The only higher input above 2 is 3 — and index 3 also wants . No conflict, so suffices.
  • Indices whose bit-0 is set: . Between them sits index 2, which wants . Since , active must override . Hence . Answer: is conflict-free (its two claimants 2 and 3 agree, and the higher one wins anyway); has a higher input (2) that disagrees with a lower one (1), forcing the guard. ✅

Level 4 — Synthesis

Recall Solution L4-Q1

Step 1 — which indices set bit-2? . Step 2 — any higher index disagree? The highest indices are exactly the ones in this set, and every index above 3 wants ; anything below 4 wants but they are all lower priority, so if any of is on it wins. WHY no suppression: a suppression term guards against a higher input wanting the bit cleared. No index ever wants . So a plain OR works. Answer: , no suppression needed; = OR of all 8. ✅

Recall Solution L4-Q2

Reasoning per claimant (highest priority wins; a lower claimant is only allowed to speak if no higher-priority input is active):

  • set bit-1 and are the top of the pile → unconditional.
  • wants , but only if nothing above index 3 is on. Above 3 are . So needs guard .
  • likewise: guard against ? No — also sets bit-1, so it agrees; but want bit-1 = 0 and outrank . Guard against : .

Both and share the same guard . Since appear standalone, the inside the guard is redundant for correctness of the value (when or is on, the standalone term already forces ), but keeping it makes the intent explicit. A minimised form (via Karnaugh maps / Boolean algebra simplification): Answer: . ✅

Recall Solution L4-Q3

Idea (this is exactly how real interrupt controllers cascade):

  • High block handles → gives .
  • Low block handles → gives .
  • means "something in the top half is active" → that is the new bit-2:
  • Choose the lower two bits from the high block if , else the low block (a 2:1 select on each bit):
  • Overall valid: .
Figure — Encoders and priority encoders

Answer: the high block's is the new MSB; two 2:1 muxes (steered by ) pick the low two bits, and . This cascades priority: any top-half request outranks the whole bottom half — precisely the "big boss wins" rule scaled up. ✅


Level 5 — Mastery

Recall Solution L5-Q1

WHY : real chips (e.g. cascaded interrupt logic) need a way to switch a block off so a higher block can take over — this is the "enable-in" pin. Multiply every output by so that zeroes everything:

Verify : . . . Output , — highest active input wins. ✅

Verify : Every term is : . Chip silent even though is on. ✅ Answer: the three enable-gated equations above; both test cases behave correctly.

Recall Solution L5-Q2

Case no input (): . The bits are treated as don't-care because commands "ignore the number." Case active only: ; , → code , but now . So the two situations differ in the bit ( vs ), which is the deciding signal — the code is only meaningful when . Why plain fails: a plain encoder has no ; both situations produce and are indistinguishable. Answer: separates them ( = empty, = ""); the plain encoder, lacking , cannot. ✅

Recall Solution L5-Q3

Simplify using absorption (from Boolean algebra simplification): The term contains as a factor, and is already a standalone term, so . The extra term vanishes: Answer: yes it is logically correct, but redundant; by absorption it reduces to the standard . The wasted AND-gate can be deleted. ✅


Recall One-line recap of the whole ladder

L1 recognise the box · L2 plug into the equations · L3 diagnose why plain encoders lie · L4 scale up (8-input, cascade two 4-blocks) · L5 add enable, prove correctness, minimise. The single thread: priority + the valid bit turn an ambiguous OR-gate into a trustworthy address generator.


Connections