Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2 — Encoders and Priority Encoders

Lesson 19 of 49 in the free Computer Organization and Architecture notes on Siksha Sarovar, written by Rohit Jangra.

Encoder

An encoder performs the inverse of a decoder: given 2^n input lines of which exactly one is active, it outputs the n-bit binary code of that line.

1. Octal-to-Binary (8-to-3) Encoder

Active inputA2A1A0
D0000
D1001
D2010
D3011
D4100
D5101
D6110
D7111
   Read each output column and OR the inputs where it is 1:

   A0 = D1 + D3 + D5 + D7        (odd-numbered lines)
   A1 = D2 + D3 + D6 + D7
   A2 = D4 + D5 + D6 + D7        (upper half)

   Hardware: just THREE OR gates. No inverters, no AND gates.

2. Decimal-to-BCD (10-to-4) Encoder

   A3 = D8 + D9
   A2 = D4 + D5 + D6 + D7
   A1 = D2 + D3 + D6 + D7
   A0 = D1 + D3 + D5 + D7 + D9

   Used in keypad-to-BCD conversion.

3. The Two Problems With a Simple Encoder

   PROBLEM 1 — ambiguity when NO input is active:
      All inputs 0  ->  output 000
      But 000 is also the code for D0 being active. Indistinguishable.

   PROBLEM 2 — garbage when TWO OR MORE inputs are active:
      D3 = 1 and D5 = 1 simultaneously
      A2 = 1 (from D5), A1 = 1 (from D3), A0 = 1 (from both)
      Output = 111 = D7   <- WRONG. Neither input was 7.

Fix for problem 1: add a valid output V = D0 + D1 + ... + D7. V = 0 means "no input active", so the 000 code is only meaningful when V = 1.

Fix for problem 2: a priority encoder.

4. Priority Encoder

A priority encoder assigns a fixed priority to the inputs; when several are active it encodes the highest-priority one and ignores the rest.

4-to-2 priority encoder (D3 highest)

D3D2D1D0A1A0V
0000XX0
0001001
001X011
01XX101
1XXX111
The X entries in the input columns mean "don't care what the lower inputs are" — that is exactly what priority means.
   A1 = D3 + D2
   A0 = D3 + D2'.D1
   V  = D3 + D2 + D1 + D0

   Verify D3=0, D2=1, D1=1, D0=1:
      A1 = 0 + 1 = 1
      A0 = 0 + 0.1 = 0        <- D2 wins over D1, code = 10 = 2  ✓
      V  = 1

8-to-3 priority encoder equations

   A2 = D7 + D6 + D5 + D4
   A1 = D7 + D6 + D5'D4'D3 + D5'D4'D2
   A0 = D7 + D6'D5 + D6'D4'D3 + D6'D4'D2'D1
   V  = D7 + D6 + D5 + D4 + D3 + D2 + D1 + D0

   Each term reads: "this input is active AND every higher one is not."

5. Encoder vs Priority Encoder

BasisSimple EncoderPriority Encoder
Multiple active inputsProduces invalid outputEncodes the highest-priority one
HardwareOR gates onlyOR + AND + inverters
Valid outputUsually absentStandard
Typical IC74148 is a priority encoder; simple encoders are rarely sold74148 (8-to-3), 74147 (10-to-4)
CostLowHigher

6. Applications

ApplicationDetail
Interrupt priority (Unit IV)Several devices raise interrupts; the priority encoder produces the vector address of the most urgent one
Keyboard encodingA pressed key drives one line; the encoder produces its code. Priority handles two simultaneous key presses
Position sensingOne-hot shaft position → binary angle
Floating-point normalisationA priority encoder finds the position of the leading 1 (leading-zero counter)
Bus arbitrationChoose which of several masters gets the bus

This is precisely the parallel priority interrupt circuit you will meet in Unit IV — the same block, one unit later.

7. Complete MSI Block Comparison

BlockInOutSelectCore equation
Multiplexer2^n data1nY = Σ m(S)·I
De-multiplexer1 data2^nnY(i) = D·m(i)
Decodern code2^n— (enable)Y(i) = m(i)
Encoder2^n one-hotn codeA(j) = OR of lines with bit j set
Priority encoder2^nn + validHighest active input wins

Combinational circuits can compute, route and select — but they cannot remember. The next lesson introduces the feedback loop that gives a circuit memory.