Ch.2: Digital Logic Eng.
Omar El Safty
Introduction
Why data is stored as binary in computers?
• Computers use logic gates
• Logic gates use one of two values: 0 or 1
Definition of a Logic gate:
A small physical device that controls the flow of electrical signals in a pre-determinant way.
Purpose of a logic gates:
• To carry out a logical operation
• To control the flow of electricity through a logic circuit
• To alter the output from given inputs
1. Types of logic gates
Six different logic gates are considered:
NOT gate AND gate OR gate
XOR gate NAND gate NOR gate
The behavior of each logic gate can be presented by constructing a truth table.
KEY TERM
Truth table – A table is used to trace the output from a logic gate or a logic circuit considering all
possible combinations of 0s and 1s that can be input.
22
Ch.2: Digital Logic Eng. Omar El Safty
2.1 NOT gate
How to draw it: Truth table:
Input Output
A X
0 1
1 0
How to write it:
X = NOT A
Explanation:
• It has one input
• Output will be 1 if the input is 0
• Output will be 0 if the input is 1
2.2 AND gate
How to draw it: Truth table:
Input Input Output
A B X
0 0 0
How to write it: 0 1 0
X = A AND B
1 0 0
Explanation: 1 1 1
• It has two inputs
• Output will be 1 if both inputs are 1
• Output will be 0 if either input is 0
23
Ch.2: Digital Logic Eng. Omar El Safty
2.3 OR gate
How to draw it: Truth table:
Input Input Output
A B X
0 0 0
How to write it:
0 1 1
X = A OR B
1 0 1
Explanation:
1 1 1
• It has two inputs
• Output will be 1 if either input is 1
• Output will be 0 if both inputs are 0
2.4 XOR gate
How to draw it: Truth table:
Input Input Output
A B X
0 0 0
How to write it:
0 1 1
X = A XOR B
1 0 1
Explanation: 1 1 0
• It has two inputs
• Output will be 1 if both inputs are different
• Output will be 0 if both inputs are 1
• Output will be 0 if both inputs are 0
24
Ch.2: Digital Logic Eng. Omar El Safty
2.5 NAND gate
How to draw it: Truth table:
Input Input Output
A B X
0 0 1
How to write it:
X = A NAND B 0 1 1
1 0 1
Explanation:
• It has two inputs 1 1 0
• Output will be 1 if either input is 0
• Output will be 0 if both inputs are 1
2.6 NOR gate
How to draw it: Truth table:
Input Input Output
A B X
0 0 1
How to write it:
X = A NOR B 0 1 0
1 0 0
Explanation:
1 1 0
• It has two inputs
• Output will be 1 if both inputs are 0
• Output will be 0 if either input is 1
25
Ch.2: Digital Logic Eng. Omar El Safty
2. Logic circuits
Definition:
A combination of logic gates to carry out a particular function.
3.1 Produce truth table for a logic circuit
Produce the truth table for the following logic circuit:
Solution:
1 Name all intermediate logic gates
R
Q
26
Ch.2: Digital Logic Eng. Omar El Safty
2 Write down the logic statements for all intermediate gates in addition to the output:
P = A OR B
Q= B NAND C
R = P XOR Q
X (Output) = R OR C
3 Draw the truth table (this logic circuit has 3 inputs which means that there are 23 = 8
possibilities):
Input Working Space Output
A B C X
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
27
Ch.2: Digital Logic Eng. Omar El Safty
4 Insert the logic statements of the intermediate gates in the truth table:
Input Working Space Output
P Q R
A B C X
= (A OR B) = (B NAND C) = (P XOR Q)
0 0 0 0 1 1
0 0 1 0 1 1
0 1 0 1 1 0
0 1 1 1 0 1
1 0 0 1 1 0
1 0 1 1 1 0
1 1 0 1 1 0
1 1 1 1 0 1
5 Complete the truth table by filling the output X column:
Input Working Space Output
P Q R X
A B C
= (A OR B) = (B NAND C) = (P XOR Q) = (R OR C)
0 0 0 0 1 1 1
0 0 1 0 1 1 1
0 1 0 1 1 0 0
0 1 1 1 0 1 1
1 0 0 1 1 0 0
1 0 1 1 1 0 1
1 1 0 1 1 0 0
1 1 1 1 0 1 1
28
Ch.2: Digital Logic Eng. Omar El Safty
Write the logic statement for the logic circuit:
1 Recall that the logic statements for all intermediate gates are:
P = A OR B
Q= B NAND C
R = P XOR Q
X (Output) = R OR C
2 Write the output (X) in terms of the input values (A, B and C):
− Expand R to P XOR Q
X = (P XOR Q) OR C
− Expand both P and Q
X = ( (A OR B) XOR (B NAND C) ) OR C
3.2 Design a logic circuit from a logic statement
Draw the logic circuit and the truth table for the following logic statement:
X = 1 if ( ( A is 1 OR B is 1 ) AND ( A is 1 AND B is 1 ) ) OR ( C is NOT 1 )
Solution:
Scan the following QR code to watch an elaborative video of the answer:
29
Ch.2: Digital Logic Eng. Omar El Safty
3.3 Wording Problems
Example:
A wind turbine has a safety system, which uses three inputs to a logic circuit. A certain
combination of conditions results in an output, X, from the logic circuit being equal to 1. When
the value X=1 then the wind turbine is shut down.
The following table shows which parameters are being monitored and form the three inputs to
the logic circuit:
The output X, will have the value of 1 if any of the following combination of conditions occur:
• either turbine speed <=1000 rpm and bearing temperature > 80oC
• or turbine speed > 1000 rpm and wind velocity > 120 kph
• or bearing temperature <=80oC and wind velocity > 120 kph
Design the logic circuit and complete the truth table to produce a value of X=1 when any of
the three conditions above occur.
Solution:
Scan the following QR code to watch an elaborative video of the answer:
30
Ch.2: Digital Logic Eng. Omar El Safty
3.4 Reducing a logic circuit to a single logic gate
The following circuit behaves the same as NOT gate:
The following circuit behaves the same as AND gate:
The following circuit behaves the same as OR gate:
IMPORTANT
Logic circuits can behave the same as a single logic gate. This can be identified if both the
logic circuit truth table output and a logic gate truth table output are the same.
31