🔹 Decoders and Encoders

Digital Logic Circuits for Data Conversion

1. What is a Decoder?

A Decoder is a combinational logic circuit that:

👉 It decodes binary input into a specific output line.

Think of it as a translator: it reads binary numbers and lights up the correct output line.

2. Example: 2-to-4 Decoder

Inputs
  • 2 binary inputs: A0, A1
  • 1 enable input: E (to activate the decoder)
Outputs
  • 4 outputs: Y0, Y1, Y2, Y3
Behavior
  • If E=0, the decoder is OFF (all outputs = 0)
  • If E=1, the decoder activates one output depending on inputs
Truth Table (2-to-4 Decoder)
E A1 A0 Y0 Y1 Y2 Y3
0 X X 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1

(X means "don't care")

Logical Expressions
Y0 = E · A1' · A0'
Y1 = E · A1' · A0
Y2 = E · A1 · A0'
Y3 = E · A1 · A0

👉 Implemented using AND gates and NOT gates.

3. Applications of Decoder

Memory Addressing

Example: A 4-to-16 decoder selects one of 16 memory blocks using a 4-bit address.

Instruction Decoding (CPU)

Converts binary machine instructions into control signals.

7-Segment Display

Converts binary input into decimal digit display.

Demultiplexing

Routes one input signal to multiple outputs.

4. What is an Encoder?

👉 The reverse of a Decoder.

  • Takes 2ⁿ input lines
  • Produces n binary outputs
  • Only one input is active at a time, and the encoder outputs the corresponding binary code

5. Example: 4-to-2 Encoder

Inputs
  • Y0, Y1, Y2, Y3 (only one is active at a time)
Outputs
  • 2-bit code: A1, A0
Truth Table (4-to-2 Encoder)
Y3 Y2 Y1 Y0 A1 A0
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
Logical Expressions
A1 = Y3 + Y2
A0 = Y3 + Y1

6. Applications of Encoder

Keyboard Encoding

Converts key presses into binary codes.

Example: Pressing "A" = binary 0100 0001.

Data Compression

Reduces multiple inputs into fewer outputs.

Multiplexing Systems

Encodes several input signals into fewer lines for transmission.

Priority Encoders

Handles multiple inputs and gives priority to the highest-order active signal (used in interrupts).

7. Decoder vs Encoder (Quick Difference)

Feature Decoder (n→2ⁿ) Encoder (2ⁿ→n)
Inputs n 2ⁿ
Outputs 2ⁿ n
Function Converts binary input → activates one output Converts active input → binary code
Example 2-to-4 Decoder 4-to-2 Encoder

In simple terms:

Decoder = expands binary → many outputs (only 1 active)

Encoder = compresses many inputs → binary code

Summary

🔹 Decoder: Takes n binary inputs and produces 2ⁿ outputs, with only one output active for each input combination.

🔹 Encoder: Takes 2ⁿ input lines and produces n binary outputs, converting the active input into a binary code.

🔹 Key Difference: Decoders expand binary inputs to multiple outputs, while encoders compress multiple inputs to binary outputs.

🔹 Applications: Both are essential in digital systems for data conversion, routing, and control.

Decoders and encoders are fundamental building blocks in digital logic design, enabling efficient data conversion and control in computer systems.