A lift shows the number of the floor that has been selected by lighting one lamp out of many. The circuit that turns a binary number into one active line is a decoder, and the circuit that works backwards from an active line to a binary number is an encoder.
Decoder
A decoder has n input lines and up to 2 to the power n output lines. For every input combination exactly one output becomes active. A 2-to-4 decoder has two inputs A and B and four outputs Y0 to Y3. Y0 = A'B', Y1 = A'B, Y2 = AB' and Y3 = AB. Each output is a minterm of the inputs.
Definition: Decoder. A combinational circuit that converts an n-bit binary input into a 2 to the power n output, activating exactly one output line for each input combination.
Table 2.5: Truth table of a 2-to-4 decoder
| A | B | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
Decoders are used to select a memory location, to drive displays and to generate the control signals of a processor. A decoder with an enable input can be combined with others to form a larger decoder.
Encoder
An encoder has 2 to the power n input lines and n output lines. Only one input is active at a time, and the output gives the binary code of that input. For a 4-to-2 encoder with inputs D0 to D3, the outputs are A1 = D2 + D3 and A0 = D1 + D3. If no input is active, or if more than one is active, the output is not meaningful.
A priority encoder removes the problem of two active inputs by giving the code of the active input with the highest priority. It is used where several devices may request attention together.
Table 2.6: Comparison of decoder and encoder
| Property | Decoder | Encoder |
|---|---|---|
| Input lines | n | 2 to the power n |
| Output lines | 2 to the power n | n |
| Active outputs | Exactly one | A binary code |
| Typical use | Memory selection | Keyboard coding |
Example 2.3: Decoding an input
Problem: A 2-to-4 decoder receives A = 1 and B = 0. Find the active output, and find the output of a 4-to-2 encoder when D3 alone is active.
Solution:
- For A = 1, B = 0 the equation Y2 = AB' equals 1, and the other outputs are 0.
- For the encoder with D3 = 1 and the others 0, A1 = D2 + D3 = 1 and A0 = D1 + D3 = 1.
Result: The decoder activates Y2. The encoder outputs 11, which is binary 3.
def decode(a, b):
return [int(not a and not b), int(not a and b),
int(a and not b), int(a and b)]
for a in (0, 1):
for b in (0, 1):
print(a, b, decode(a, b))
Output
0 0 [1, 0, 0, 0]
0 1 [0, 1, 0, 0]
1 0 [0, 0, 1, 0]
1 1 [0, 0, 0, 1]
Common mistakes
- Believing that more than one decoder output can be active for one input.
- Using an ordinary encoder when two inputs may be active together.
- Mixing up the number of inputs and outputs of a decoder and an encoder.
Key takeaways
- A decoder activates one output line for each input code.
- An encoder gives the binary code of the single active input.
- A priority encoder resolves several active inputs.
- Each decoder output is a minterm of its inputs.
Practice questions
- How many outputs does a 3-to-8 decoder have?
- What is a priority encoder?
- Write the equation of output Y3 of a 2-to-4 decoder.
Answers to the practice questions
- Eight.
- An encoder that outputs the code of the highest-priority input when several inputs are active.
- Y3 = A·B.
Sources
- Official BCA syllabus Computer Architecture, course code 25BCA401DS02, Unit II
