You are on page 1of 53

CS270: INTRODUCTION TO COMPUTER

ENGINEERING

Decoders and Encoders

Decoders and Encoders 13th January 2023 1


Content
• Introduction
• Decoders
• BCD -to- Decimal Decoders
• Examples of Decoders
• Encoders
• Decimal-BCD Priority Encoder
• Revision

Decoders and Encoders 13th January 2023 2


Introduction
• Binary decoders
– Converts an n-bit code to a single active
output
– Can be developed using AND/OR gates
– Can be used to implement logic circuits
• Binary encoders
– Converts one of 2n inputs to an n-bit output
– Useful for compressing data
– Can be developed using AND/OR gates
• Both encoders and decoders are extensively
used in digital systems
Decoders and Encoders 13th January 2023 3
Decoders
• A decoder is a logic circuit that accepts a set of inputs
that represents a binary number and activates only the
output that corresponds to the input number
• In other words, a decoder circuit looks at its inputs,
determines which binary number is present there, and
activates the one output that corresponds to that
number ; all other outputs remain inactive
• In its general form, a decoder has N input lines to
handle N bits and form one to 2 N output lines to indicate
the presence of one or more N-bit combinations

Decoders and Encoders 13th January 2023 4


Decoders (contd.)
⚫ TstA decoder has:
− N inputs
− 2N outputs
⚫ A decoder selects one of 2N outputs by
decoding the binary value on the N inputs.
⚫ The decoder generates all of the minterms of
the N input variables.
− Exactly one output will be active for
each combination of the inputs.
What does “active” mean?

Decoders and Encoders 13th January 2023 5


General Decoder Diagram

• There are 2N possible input combinations, from A0 to


AN−1.
• For each of these input combinations only one of the M
outputs will be active HIGH (1), all the other outputs are
LOW (0)
Decoders and Encoders 13th January 2023 6
Decoders – Basic Binary Function
• An AND gate can be used as the basic decoding
element because it produces a HIGH output only
when all inputs are HIGH
• Decoding logic for the binary code 1001 with an
active-HIGH output.

Decoders and Encoders 13th January 2023 7


Decoders (contd.)

• Decoders are used in many types of applications.


One example is in computers for I/O selection as in
previous slide

• Computer must communicate with a variety of


external devices called peripherals by sending
and/or receiving data through what is known as
input/output (I/O) ports

Decoders and Encoders 13th January 2023 8


Decoders (contd.)
• Each I/O port has a number, called an address,
which uniquely identifies it. When the computer
wants to communicate with a particular device, it
issues the appropriate address code for the I/O port
to which that particular device is connected. The
binary port address is decoded and appropriate
decoder output is activated to enable the I/O port

• Binary data are transferred within the computer on a


data bus, which is a set of parallel lines

Decoders and Encoders 13th January 2023 9


BCD -to- Decimal Decoders
• The BCD- to-decimal decoder converts each BCD
code into one of Ten Positionable decimal digit
indications. It is frequently referred as a 4-line -to-
10 line decoder
• The method of implementation is that only ten
decoding gates are required because the BCD
code represents only the ten decimal digits 0
through 9.
• Each of these decoding functions is implemented
with NAND gates to provide active -LOW outputs.
If an active HIGH output is required, AND gates
are used for decoding
Decoders and Encoders 13th January 2023 10
Examples of Decoders

Decoders and Encoders 13th January 2023 11


Decoders (contd.)

W = A'.B'
Out0 W
B I0 Out1 X X = A.B'
A I1 Out2 Y Y = A'.B
Out3 Z
msb Z = A.B
Active-high outputs

A B W X Y Z
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 and Encoders 13th January 2023 12


Decoders (contd.)

W = (A'.B')'
Out0 W
B I0 Out1 X X = (A.B')'
A I1 Out2 Y Y = (A'.B)'
Out3 Z
msb Z = (A.B)'
Active-low outputs

A B W X Y Z
0 0 0 1 1 1
0 1 1 0 1 1
1 0 1 1 0 1
1 1 1 1 1 0

Decoders and Encoders 13th January 2023 13


Decoders (contd.)

msb

Decoders and Encoders 13th January 2023 14


Decoders with Enable

Out0 W
B I0
high-level Out1 X
enable A I1
Out2 Y
Out3 Z
Enable En

En A B W X Y Z
1 0 0 1 0 0 0
1 0 1 0 1 0 0
enabled
1 1 0 0 0 1 0
1 1 1 0 0 0 1
disabled 0 x x 0 0 0 0

Decoders and Encoders 13th January 2023 15


Decoders With Enable (contd.)

Out0 W
B I0
low-level Out1 X
enable A I1
Out2 Y
Out3 Z
Enable En

En A B W X Y Z
0 0 0 1 0 0 0
0 0 1 0 1 0 0
enabled
0 1 0 0 0 1 0
0 1 1 0 0 0 1
disabled 1 x x 0 0 0 0

Decoders and Encoders 13th January 2023 16


2-to-4-Line Decoder (with Enable input)-Active
LOW output

Decoders and Encoders 13th January 2023 17


2-to-4-Line Decoder
(with Enable input)-Active LOW output (2)
• The circuit operates with complemented outputs
and a complement enable input. The decoder is
enabled when E is equal to 0.
• Only one output can be equal to 0 at any given
time, all other outputs are equal to 1.
• The output whose value is equal to 0 represents
the minterm selected by inputs A and B
• The circuit is disabled when E is equal to 1.

Decoders and Encoders 13th January 2023 18


3-8 line decoder (active-HIGH)

19
Decoders and Encoders 13th January 2023 19
3-8 line decoder (active-HIGH) (contd.)
• This decoder can be referred to in several
ways. It can be called a 3-line-to- 8-line decoder,
because it has three input lines and eight output
lines.
• It could also be called a binary-octal decoder or
converters because it takes a three bit binary
input code and activates the one of the eight
outputs corresponding to that code. It is also
referred to as a 1-of-8 decoder, because only 1
of the 8 outputs is activated at one time.

Decoders and Encoders 13th January 2023 20


A simplified Computer I/O Port System with a Port Address
Decoder with only Four Address Lines Shown

Decoders and Encoders 13th January 2023 21


Decoders (contd.)
• A digital circuit that converts an input binary code into a
single numeric output.

A0 O0
A1 O1
A2 O2
DECODER O3
O4
O5
O6
O7

• Binary Code Input


• Only One Output
• Activated at a Time
Decoders and Encoders 13th January 2023 22
THE 8421 BCD CODE

• BCD stands for Binary-Coded Decimal.

• A BCD number is a four-bit binary group that


represents one of the ten decimal digits 0 through
9.
• Example:
• Decimal number 4926 4 9 2 6

• 8421 BCD coded number 0100 1001 0010 0110

Decoders and Encoders 13th January 2023 23


Decoders (contd.)
• Decoder: Popular combinational
logic building block, in addition to
d0 1 d0 0 d0 0 d0 0
logic gates
0 i0 d1 0 1 i0 d1 1 0 i0 d1 0 1 i0 d1 0
– Converts input binary number to
0 i1 d2 0 0 i1 d2 0 1 i1 d2 1 1 i1 d2 0
one high output
d3 0 d3 0 d3 0 d3 1
• 2-input decoder: four possible
input binary numbers
– So has four outputs, one for each d0 0
i1’i0’ d0
possible input binary number 1 i0 d1 0
• Internal design i1’i0 d1 1 i1 d2 0
– AND gate for each output to e d3 1
detect input combination i1i0’ d2
1
• Decoder with enable e i1i0 d3 d0 0
– Outputs all 0 if e=0 1 i0 d1 0
– Regular behavior if e=1 1 i1 d2 0

• n-input decoder: 2n outputs i1 i0


e d3 0
a
a
0

Decoders and Encoders 13th January 2023 24


Encoders

Decoders and Encoders 13th January 2023 25


Encoders
• An encoder is a combinational logic circuit that
essentially performs a “reverse” of decoder
functions
• TstAn encoder accepts an active level on one of
its inputs, representing digit, such as a decimal
or octal digits, and converts it to a coded output
such as BCD or binary
• Encoders can also be devised to encode various
symbols and alphabetic characters
• The process of converting from familiar symbols
or numbers to a coded format is called
encoding
Decoders and Encoders 13th January 2023 26
Encoders (contd.)
• Most decoders accept an input code and
produce a HIGH ( or a LOW) at one and only
one output line
• In otherworlds , a decoder identifies,
recognizes, or detects a particular code. The
opposite of this decoding process is called
encoding and is performed by a logic circuit
called an encoder
• An encoder has a number of input lines, only
one of which input is activated at a given time
and produces an N-bit output code, depending
on which input is activated

Decoders and Encoders 13th January 2023 27


Encoders (contd.)
⚫ An encoder has:
− 2N inputs
− N outputs
⚫ An encoder outputs the binary value of the
selected (or active) input.
⚫ An encoder performs the inverse operation of a
decoder.
⚫ Issues
− What if more than one input is active?
− What if no inputs are active?

Decoders and Encoders 13th January 2023 28


General Encoder Diagram

Decoders and Encoders 13th January 2023 29


Encoders (contd.)

D I0
C I1 Out0 Z
Out1 Y
B I2
A I3

A B C D Y Z
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1

Decoders and Encoders 13th January 2023 30


Priority Encoders
⚫ If more than one input is active, the higher-order
input has priority over the lower-order input.
− The higher value is encoded on the output
⚫ A valid indicator, d, is included to indicate whether
or not the output is valid.
− Output is invalid when no inputs are active
⚫ d=0
− Output is valid when at least one input is
active
⚫ d=1
Why is the valid indicator needed?

Decoders and Encoders 13th January 2023 31


Priority Encoders (contd.)

msb

Valid bit

Decoders and Encoders 13th January 2023 32


Logic circuit for octal-to binary encoder
(8-line- 3-line )

Decoders and Encoders 13th January 2023 33


Truth table for octal-to binary encoder
(8-line- 3-line)

• A low at any single input will produce the output binary code
corresponding to that input. For instance , a low at A3’ will produce
O2 =0, O1=1 and O0 =1, which is binary code for 3. Ao’ is not
connected to the logic gates because the encoder outputs always
be normally at 0000 when none of the inputs is LOW
Decoders and Encoders 13th January 2023 34
Design of 4-input Priority Encoder
( 4-line-to 2 line priority encoder)
• TstA priority encoder is an encoder that includes the priority
function
• If two or more inputs are equal to 1 at the same time, the
input having the highest priority will take precedence.
• Truth Table of a 4-input Priority Encoder:
Inputs Outputs
D0 D1 D2 D3 x y V
0 0 0 0 X X 0
1 0 0 0 0 0 1
X 1 0 0 0 1 1
X X 1 0 1 0 1
X X X 1 1 1 1
Decoders and Encoders 13th January 2023 35
Design of 4-input Priority Encoder
( 4-line-to 2 line priority encoder) (contd.)
• In addition to two outputs x, and y, the truth table has a third
output designated by V, which is a valid bit indicator that is
set 1 when one or more inputs are equal to 1. If all inputs
are 0, there is no valid input and V is equal to 0
• X’s in the output column indicate don’t care conditions, the
X’s in the input columns are useful for representing a truth
table in condensed form
• The higher the subscript number, the higher the priority of
the input. Input D3 has the highest priority, so regardless of
the values of the other inputs, when this input is 1, the
output for xy is 11 (binary 3)

Decoders and Encoders 13th January 2023 36


Design of 4-input Priority Encoder
( 4-line-to 2 line priority encoder) (contd.)

Decoders and Encoders 13th January 2023 37


Decimal-BCD Priority Encoder
• Encoder will produce a BCD output
corresponding to the highest-order decimal digit
input that is active and will ignore any other
lower order active inputs.

• For instance if the input 6 and the 3 are active,


the output will be 1001, which is the inverse
value of BCD output 0110 (which represents
decimal 6)

Decoders and Encoders 13th January 2023 38


Revision

Decoders and Encoders 13th January 2023 39


Binary Decoder

• Black box with n input lines and 2n output lines


• Only one output is a 1 for any given input

n Binary 2n outputs
inputs Decoder

Decoders and Encoders 13th January 2023 40


2-to-4 Binary Decoder
Truth Table:

X Y F0 F1 F2 F3
0 0 1 0 0 0
0 1 0 1 0 0 F0 = X'Y'
1 0 0 0 1 0
1 1 0 0 0 1
F1 = X'Y

• From truth table, circuit for F2 = XY'


2x4 decoder is:
• Note: Each output is a 2- F3 = XY
variable minterm (X'Y', X'Y,
XY' or XY)

F0
X Y
X 2-to-4 F1
Y Decoder F2
F3

Decoders and Encoders 13th January 2023 41


3-to-8 Binary Decoder
Truth Table: F0 = x'y'z'
x y z F0 F1 F2 F3 F4 F5 F6 F7 F1 = x'y'z
0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0 F2 = x'yz'
0 1 0 0 0 1 0 0 0 0 0
0 1 1 0 0 0 1 0 0 0 0 F3 = x'yz
1 0 0 0 0 0 0 1 0 0 0
1 0 1 0 0 0 0 0 1 0 0 F4 = xy'z'
1 1 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 1 F5 = xy'z

F6 = xyz'
F0
F1 F7 = xyz
X
F2
Y
3-to-8
F3
Z
Decoder F4
F5
F6
x y z
F7

Decoders and Encoders 13th January 2023 42


Implementing Functions Using Decoders
• Any n-variable logic function can be implemented
using a single n-to-2n decoder to generate the
minterms
– OR gate forms the sum.
– The output lines of the decoder corresponding to
the minterms of the function are used as inputs to
the or gate.
• Any combinational circuit with n inputs and m
outputs can be implemented with an n-to-2n decoder
with m OR gates.
• Suitable when a circuit has many outputs, and each
output function is expressed with few minterms.
Decoders and Encoders 13th January 2023 43
Implementing Functions Using Decoders

• Example: Full adder x


0
y
0
z
0
C S
0 0
S(x, y, z) = S (1,2,4,7) 0 0 1 0 1
C(x, y, z) = S (3,5,6,7) 0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1

3-to-8 0
Decoder 1 S
2
x S2 3
y S1 4
5 C
z S0 6
7

Decoders and Encoders 13th January 2023 44


Standard MSI Binary Decoders Example
74138 (3-to-8 decoder)

(a) Logic circuit.


(b) Package pin configuration.
(c) Function table.
Decoders and Encoders 13th January 2023 45
Building a Binary Decoder with NAND Gates
• Start with a 2-bit decoder
– Add an enable signal (E) Note: use of NANDs
only one 0 active!
if E = 0

Decoders and Encoders 13th January 2023 46


Use two 3 to 8 decoders to make 4 to 16 decoder
• Enable can also be active high
• In this example, only one decoder can be active at
a time.
• x, y, z effectively select output line for w

Decoders and Encoders 13th January 2023 47


Encoders
• If the a decoder's output code has fewer bits than the
input code, the device is usually called an encoder.
e.g. 2n-to-n
• The simplest encoder is a 2n-to-n binary encoder
– One of 2n inputs = 1
– Output is an n-bit binary number

Binary
2n encoder n
. .
inputs . . outputs
. .

Decoders and Encoders 13th January 2023 48


8-to-3 Binary Encoder
At any one time, only Inputs Outputs
one input line has a value of 1.
I0 I1 I2 I3 I4 I5 I6 I7 y2 y1 y0
1 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0 1
0 0 0 0 0 0 1 0 1 1 0
0 0 0 0 0 0 0 1 1 1 1
I0
I1 y2 = I4 + I5 + I6 + I7
I2
I3 y1 = I2 + I3 + I6 + I7
I4
I5
I6
I7 y0 = I1 + I3 + I5 + I7

Decoders and Encoders 13th January 2023 49


8-to-3 Priority Encoder
• What if more than one input line has a value of 1?
• Ignore “lower priority” inputs.
• Idle indicates that no input is a 1.
• Note that polarity of Idle is opposite

Inputs Outputs
I0 I1 I2 I3 I4 I5 I6 I7 y2 y1 y0 Idle
0 0 0 0 0 0 0 0 x x x 1
1 0 0 0 0 0 0 0 0 0 0 0
X 1 0 0 0 0 0 0 0 0 1 0
X X 1 0 0 0 0 0 0 1 0 0
X X X 1 0 0 0 0 0 1 1 0
X X X X 1 0 0 0 1 0 0 0
X X X X X 1 0 0 1 0 1 0
X X X X X X 1 0 1 1 0 0
X X X X X X X 1 1 1 1 0

Decoders and Encoders 13th January 2023 50


Priority Encoder (8 to 3 encoder)
• Assign priorities to the inputs
• When more than one input are asserted, the output generates the code
of the input with the highest priority
• Priority Encoder :
H7=I7 (Highest Priority)
H6=I6.I7’ Priority encoder
H5=I5.I6’.I7’ Priority Circuit Binary encoder
H4=I4.I5’.I6’.I7’
H3=I3.I4’.I5’.I6’.I7’ I0 I0 H0 I0
H2=I2.I3’.I4’.I5’.I6’.I7’ I1 I1 H1 I1
H1=I1. I2’.I3’.I4’.I5’.I6’.I7’ I2 I2 H2 I2 Y0
Y0
H0=I0.I1’. I2’.I3’.I4’.I5’.I6’.I7’ I3 I3 H3 I3 Y1
Y1
IDLE= I0’.I1’. I2’.I3’.I4’.I5’.I6’.I7’ I4 I4 H4 I4 Y2
Y2
• Encoder I5 I5 H5 I5
Y0 = I1 + I3 + I5 + I7 I6 I6 H6 I6
Y1 = I2 + I3 + I6 + I7 I7 I7 H7 I7
Y2 = I4 + I5 + I6 + I7
IDLE IDLE

Decoders and Encoders 13th January 2023 51


Encoder Application (Monitoring Unit)
Encoder identifies the requester and encodes the value
Controller accepts digital inputs.

Alarm Contoller
Signal Response

Machine 1

Machine 2 Machine Action


Code
Encoder Controller

Machine n

Decoders and Encoders 13th January 2023 52


End

Decoders and Encoders 13th January 2023 53

You might also like