Encoders and priority encoders
WHAT is an encoder?
WHY does this exist? Imagine 8 buttons on a keypad. Running 8 separate wires everywhere is wasteful. Instead, encode "which button" into just 3 wires (). Compression of information from position into number.
HOW to derive a 4-to-2 encoder from scratch
We have inputs . Only one is HIGH at a time. Outputs should give the index in binary.
Step 1 — build the truth table. (Why? Because the whole behaviour is just "index → binary".)
| Active input | ||
|---|---|---|
| 0 | 0 | |
| 0 | 1 | |
| 1 | 0 | |
| 1 | 1 |
Step 2 — read off which inputs make each output 1.
- when the active input is or (the odd indices).
- when the active input is or (indices ).
Why this step? Each output bit is just "which indices have a 1 in that bit position?" That's literally the binary representation.
Step 3 — generalize. For a -to- encoder:
Why? Output bit must be 1 exactly for those input indices whose -th binary digit is 1.
The PROBLEM with a plain encoder
Priority Encoder — WHAT and WHY
WHY: real systems (interrupts, keypads) can have several requests at once. We need a deterministic rule: "serve the most important one." Priority = a tie-breaker.
Deriving the 4-input priority encoder
Priority: . Use for "don't care".
| 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 |
Step 1 — : valid whenever anything is on. Why? OR of all inputs = "at least one active."
Step 2 — : should be 1 for indices 2 and 3. present ⇒ . Or present and no higher one blocks it — but since for both 2 and 3 anyway: Why the same as before? Both indices 2 and 3 have bit-1 set, and dominates but both give , so no suppression needed for this bit.
Step 3 — : 1 for indices 1 and 3. But must be suppressed if a higher input ( or ) is active (higher ones give ). Why the ? If is active it outranks ; index 2 wants . So only counts when is off. always forces regardless (index 3 is odd).
Worked Examples
Recall Feynman: explain to a 12-year-old
Imagine a row of 8 doorbells, numbered 0 to 7. Instead of running 8 long wires to grandma's room, we send just 3 wires that spell out the number of whichever bell was rung — in binary (like 0-1-1 = bell 3). That gadget is an encoder. But what if two kids ring bells at the same time? A plain encoder gets confused and shouts a wrong number. So we add a rule: "always report the biggest bell number." That polite, rule-following version is a priority encoder. And a tiny extra light () turns on only when someone actually rang, so grandma can tell the difference between "bell 0" and "no one is here."
Flashcards
What is an encoder (in terms of inputs/outputs)?
Encoder vs decoder?
Give the 4-to-2 plain encoder equations.
Why does a plain encoder fail with multiple active inputs?
Why does a plain encoder fail with all-zero input?
What extra output fixes the all-zero ambiguity?
What does a priority encoder do differently?
Give the 4-input priority encoder equations.
Why the term in ?
General rule for output bit of an encoder?
Connections
- Decoders — the exact inverse operation of an encoder.
- Multiplexers — muxes select data; encoders select which line is active.
- Interrupt controllers — real hardware use of priority encoders (which IRQ to serve first).
- Boolean algebra simplification — used to derive/minimize the OR-based equations.
- Karnaugh maps — tool to derive priority-encoder logic with don't-cares.
- Combinational circuits — parent topic; encoders are memoryless logic.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, encoder ek aisa circuit hai jo decoder ka ulta kaam karta hai. Decoder chhoti si binary number leke lines me se ek ko HIGH karta hai. Encoder ulta — usme input lines hoti hain, aur jo bhi line active (HIGH) hoti hai, uska index binary me output kar deta hai. Matlab sawaal simple hai: "kaunsi line dabi?" — aur jawaab number ki form me. 8 buttons ko 8 wires ki jagah sirf 3 wires me pack kar dena — yehi iska magic hai ().
Har output bit ka rule yaad rakho: tab 1 hoga jab active input ka index ke -th bit me 1 ho. Isliye 4-to-2 me (odd indices) aur (indices ). Bas OR gates, koi AND nahi — kyunki assume karte hain ek hi input active hai.
Lekin problem tab aati hai jab do inputs ek saath active ho jaayein. Plain encoder confuse ho jaata hai aur galat number de deta hai (jaise aur dono on ⇒ output 3, jo galat hai). Aur agar kuch bhi press na ho, to output aata hai jo " active" jaisa dikhta hai — dono me farq hi nahi chalega. Iska solution hai priority encoder: jab multiple inputs on hon, sabse bada index jeet jaata hai (Big Boss Wins), aur ek chhota Valid bit batata hai ki koi input sach me active hai ya nahi.
Yeh cheez real life me bahut important hai — jaise interrupt controller me, jab kai devices ek saath CPU se attention maangte hain, priority encoder decide karta hai kise pehle serve karna hai. Toh formula ratne se pehle rule samjho: OR se bits banao, aur priority ke liye chhote inputs ko bade input se suppress karo (isliye me aaya).