Encoders and Priority Encoders
In the previous article, we examined decoders that convert an $n$-bit binary code into one active output. This article examines the inverse operation: encoding multiple input lines into a compact binary index. In microprocessor architectures, multiple peripherals can assert interrupt requests simultaneously. A priority encoder resolves concurrent requests and identifies the highest-priority device. Priority encoders also detect leading zeros during floating-point arithmetic normalization and resolve bus contention in shared arbiter circuits.
Definition of Binary Encoders
A basic binary encoder accepts $2^n$ input lines and generates an $n$-bit binary output code. The circuit assumes that exactly one input line is asserted high at any given time. The binary output pattern represents the numerical index of that active input line.
The 4-to-2 Binary Encoder
A 4-to-2 encoder receives four input lines ($I_3, I_2, I_1, I_0$) and produces two binary output bits ($Y_1, Y_0$). Table 1 lists the functional truth table under the single-active-input condition:
| $I_3$ | $I_2$ | $I_1$ | $I_0$ | $Y_1$ | $Y_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 |
Output bit $Y_1$ is active when input $I_2$ or $I_3$ is high. Output bit $Y_0$ is active when input $I_1$ or $I_3$ is high. The resulting Boolean equations are:
$$Y_1 = I_2 + I_3$$
$$Y_0 = I_1 + I_3$$
Figure 1 shows the gate-level schematic. The circuit requires only two 2-input OR gates.
Limitations of Basic Encoders
Basic encoders exhibit two severe functional limitations in physical systems:
- Multiple Active Inputs: If more than one input asserts high simultaneously, the circuit produces an erroneous code. For example, if $I_1 = 1$ and $I_2 = 1$, the outputs evaluate to $Y_1 = 1$ and $Y_0 = 1$ ($11_2 = 3$). The circuit reports input 3, even though input 3 is inactive.
- Ambiguous Inactive State: When all inputs are 0, the outputs evaluate to $Y_1 = 0$ and $Y_0 = 0$. The downstream system cannot distinguish between “input 0 is active” and “no inputs are active.”
Practical hardware systems require priority encoders to resolve these ambiguities.
Priority Encoders and Don’t-Care States
A priority encoder assigns a strict hierarchical ranking to its input lines. When multiple inputs assert high simultaneously, the encoder outputs the binary index of the highest-priority active input. Lower-priority active inputs are ignored. A priority encoder also provides a valid output flag ($V$). Flag $V$ asserts high if at least one input is active and drops low when all inputs are inactive.
Table 2 lists the truth table for a 4-to-2 priority encoder where $I_3$ has the highest priority and $I_0$ has the lowest priority:
| $I_3$ | $I_2$ | $I_1$ | $I_0$ | $Y_1$ | $Y_0$ | $V$ |
|---|---|---|---|---|---|---|
| 1 | X | X | X | 1 | 1 | 1 |
| 0 | 1 | X | X | 1 | 0 | 1 |
| 0 | 0 | 1 | X | 0 | 1 | 1 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
The $X$ symbols represent don’t-care conditions. Because higher-priority inputs override lower-priority inputs, the downstream state of lower-priority inputs does not affect the output.
Logic Minimization for the 4-to-2 Priority Encoder
We derive the Boolean equations for $Y_1$, $Y_0$, and $V$ using Boolean algebra and Karnaugh maps.
Derivation of $Y_1$
Output $Y_1$ is 1 when $I_3 = 1$ or when $I_3 = 0$ and $I_2 = 1$:
$$Y_1 = I_3 + \overline{I_3}I_2 = I_3 + I_2$$
Because inputs 2 and 3 both have bit 1 set in their binary indices, priority does not change the equation for $Y_1$.
Derivation of $Y_0$
Output $Y_0$ is 1 when $I_3 = 1$ (input 3 wins) or when $I_3 = 0$, $I_2 = 0$, and $I_1 = 1$ (input 1 wins). Figure 2 shows the corresponding 4-variable Karnaugh map with rows $I_3 I_2$ and columns $I_1 I_0$.
Grouping the minterms yields:
$$Y_0 = I_3 + \overline{I_3},\overline{I_2}I_1 = I_3 + \overline{I_2}I_1$$
Derivation of $V$
Valid flag $V$ asserts high when any input line is logic 1:
$$V = I_3 + I_2 + I_1 + I_0$$
The complete 4-to-2 priority encoder requires one inverter, one AND gate, and three OR gates.
Cascaded 8-to-3 Priority Encoder Architecture
You can construct wider priority encoders by cascading 4-to-2 modules. Figure 3 shows an 8-to-3 priority encoder constructed from two 4-to-2 priority encoders.
The upper encoder processes high-priority inputs $I_7 \dots I_4$. The lower encoder processes low-priority inputs $I_3 \dots I_0$.
- The upper valid signal ($V_H$) indicates if any high-priority input is active.
- Output $Y_2$ connects directly to $V_H$ ($Y_2 = V_H$).
- A 2-to-1 multiplexer controlled by $V_H$ selects between the upper and lower output pairs $(Y_1, Y_0)$.
- The global valid signal is $V = V_H + V_L$.
If any input in the upper group is active ($V_H = 1$), the multiplexer routes the upper encoder output and suppresses the lower group.
Hardware Applications
Priority encoders serve critical functions across digital computer systems:
- Vectored Interrupt Controllers: When peripheral devices (such as timers, UARTs, and DMA controllers) assert interrupt request lines simultaneously, the priority encoder selects the highest-priority interrupt index and supplies the interrupt vector address to the CPU.
- Floating-Point Normalization: In floating-point arithmetic units, a priority encoder (or leading-zero counter) locates the most significant 1 in an unnormalized mantissa to determine the necessary barrel shift amount.
- Shared Bus Arbitration: In multi-master system buses (such as PCI Express or AXI), arbitration logic uses priority encoders to award bus ownership to the highest-priority requesting master.
Practice Exercises
Problem 1: Design a 4-to-2 priority encoder in which input $I_0$ has the highest priority and input $I_3$ has the lowest priority. Formulate the Boolean equations for $Y_1$, $Y_0$, and $V$.
View Solution
Table 3 lists the inverted-priority truth table:
| $I_0$ | $I_1$ | $I_2$ | $I_3$ | $Y_1$ | $Y_0$ | $V$ |
|---|---|---|---|---|---|---|
| 1 | X | X | X | 0 | 0 | 1 |
| 0 | 1 | X | X | 0 | 1 | 1 |
| 0 | 0 | 1 | X | 1 | 0 | 1 |
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Output $Y_1$ is 1 when input 2 or 3 wins ($I_0 = 0$ and $I_1 = 0$): $$Y_1 = \overline{I_0},\overline{I_1}(I_2 + I_3) = \overline{I_0},\overline{I_1}I_2 + \overline{I_0},\overline{I_1}I_3$$
Output $Y_0$ is 1 when input 1 wins ($I_0 = 0, I_1 = 1$) or input 3 wins ($I_0 = 0, I_1 = 0, I_2 = 0, I_3 = 1$): $$Y_0 = \overline{I_0}(I_1 + \overline{I_2}I_3)$$
Valid flag $V$: $$V = I_0 + I_1 + I_2 + I_3$$
Problem 2: A standard 4-to-2 priority encoder ($I_3$ highest priority) receives inputs $I_3 = 1$, $I_2 = 1$, $I_1 = 0$, and $I_0 = 0$. Determine outputs $Y_1, Y_0$ and valid flag $V$.
View Solution
Calculate each term using the priority equations:
- $Y_1 = I_3 + I_2 = 1 + 1 = 1$
- $Y_0 = I_3 + \overline{I_2}I_1 = 1 + (0)(0) = 1$
- $V = 1 + 1 + 0 + 0 = 1$
The output is $Y_1 Y_0 = 11_2$ (index 3) and $V = 1$. The active state of input $I_2$ is ignored because $I_3$ has higher priority.
Problem 3: An 8-to-3 priority encoder ($I_7$ highest priority) receives inputs where $I_5 = 1$, $I_3 = 1$, $I_2 = 1$, and $I_0 = 1$. All other inputs are 0. Determine the 3-bit binary output and valid flag.
View Solution
The highest active input is $I_5$. The encoder generates the binary index of input 5:
- Binary output: $Y_2 Y_1 Y_0 = 101_2$
- Valid output: $V = 1$
All active inputs below $I_5$ ($I_3, I_2, I_0$) are suppressed by priority masking.
In the next article, we examine digital magnitude comparators used to evaluate numerical equality and inequality.