G3 Computing Textbook Chapter 03
G3 Computing Textbook Chapter 03
03 Logic Gates
52
53
54
3.1 Boolean Logic
ER MS
KEY T
Boolean
A data type representing either True or
False
Georgle Boole
ER MS
KEY T
We use a truth table to show the resulting
output for every possible combination of
inputs. Tables 3.2.1 to 3.2.3 show the truth
tables for logic gates with one, two and three Truth table
inputs respectively. Notice that there is only A table that shows the resulting output for every
one output column in the truth tables. This possible combination of inputs
is because we will be using these tables for
logic gates that have only one output.
55
Input A Output Input A Input B Input C Output
0 0 0 0
1 0 0 1
Table 3.2.1 Truth table for logic gate with one input
0 1 0
0 1 1
Input A Input B Output
1 0 0
0 0
1 0 1
0 1
1 0 1 1 0
1 1 1 1 1
Table 3.2.2 Truth table for logic gate with two inputs Table 3.2.3 Truth table for logic gate with three inputs
1 Determine the number of rows in the truth table, which is equal to 2n, where n refers to the number
of inputs.
For example, if there are two inputs, the truth table will have 22 = 4 rows. If there are three inputs,
the truth table will have 23 = 8 rows.
2 Fill in the input columns in ascending order using the binary number system.
For example, in a three-input system, the inputs start from 000 in the first row, followed by 001 in
the second, 010 in the third and so on, up to 111 in the last row.
The output is determined by the type of logic gate, as described in the next section.
LEARNING OUTCOMES
1.3.3 Draw symbols and construct truth tables for AND, OR, NOT, NAND, NOR and XOR logic gates.
ER MS
A logic gate is an electrical circuit KEY T
that performs logical operations
Logic gate
based on one or more inputs and
An electrical circuit that performs logical operations based on one
produces a single output.
or more inputs and produces a single output
In this section, you will learn
Logical operation
about the six basic types of logic
An operation that acts on binary inputs to produce an output
gates (AND, OR, NOT, NAND, NOR
according to the laws of Boolean logic
and XOR) as well as their functions
and applications.
56
3.3.1 AND Gate
The AND gate has two inputs and one output. The logic symbol and Boolean statement representing the
AND gate are shown in Table 3.3.1. Boolean statements are also known as logic statements.
A
AND Q Q=A•B
B
The AND gate performs the AND operation, which We can make use of declarative statements that are
gives an output of 1 only when both inputs are 1. either True (1) or False (0), to help us make sense
The truth table in Table 3.3.2 illustrates this. of Table 3.3.2. For example, to take part in a talent
show competition, applicants may be screened for
their ability to sing, and their ability to dance, as
illustrated in Table 3.3.3.
Input A Input B Output Q Can sing Can dance Can sing AND dance
Table 3.3.2 Truth table of the AND gate Table 3.3.3 Declarative statements using AND
3.3.2 OR Gate
The OR gate has two inputs and one output. The logic symbol and Boolean statement representing the OR
gate are shown in Table 3.3.4.
A
OR Q Q=A+B
B
57
The OR gate performs the OR operation, which gives an
output of 1 when at least one of its inputs is 1. The truth
table in Table 3.3.5 illustrates this.
0 0 0
0 1 1
1 0 1
1 1 1
We can make use of declarative statements that are either True (1) or False (0), to help us make sense of
Table 3.3.5. For example, when installing an anti-burglary alarm, we may expect the alarm to be triggered
when either a window or a door has been forced open without the use of a key, as illustrated in Table 3.3.6.
Window is forced open Door is forced open Window OR door is forced open
The NOT gate has only one input and one output. The logic symbol and Boolean statement representing
the NOT gate are shown in Table 3.3.7.
NOT A Q Q=A
The truth table in Table 3.3.8 illustrates this. Table 3.3.8 Truth table of the NOT gate
58
3.3.4 NAND Gate
The NAND gate has two inputs and one output. The logic symbol and Boolean statement representing the
NAND gate are shown in Table 3.3.9.
A
NAND Q Q=A•B
B
The NAND gate performs the NAND operation, which gives an output of 0 only when both inputs are 1. The
truth table in Table 3.3.10 illustrates this.
0 0 1
0 1 1
1 0 1
1 1 0
U
DID YO
?
KNO W Power (GND) Power (5V)
$
"##
$&
'()
Input A !
%&..
Input B
!
Output A• B
!
+,-
% *
Actual logic gates are usually very small and The above chip contains 4 NAND gates as shown in
made using different forms of silicon. The the accompanying diagram.
above photo shows a magnified NAND gate
found on a computer chip.
59
3.3.5 NOR Gate
The NOR gate has two inputs and one output. The logic symbol and Boolean statement representing the
NOR gate are shown in Table 3.3.11.
A
NOR Q Q=A+B
B
The NOR gate performs the NOR operation, which gives an output of 0 when at least one of its inputs is 1.
The truth table in Table 3.3.12 illustrates this.
0 0 1
0 1 0
1 0 0
1 1 0
The XOR gate has two inputs and one output. The logic symbol and Boolean statement representing the
XOR gate are shown in Table 3.3.13.
A
XOR Q Q=A B
B
60
The XOR gate performs the XOR operation, which gives
an output of 1 when exactly one of its inputs is 1. The
truth table in Table 3.3.14 illustrates this.
0 0 0
0 1 1
1 0 1
1 1 0
We can make use of declarative statements that are either True (1) or False (0), to help us make sense of
Table 3.3.14. For example, when ordering from a set lunch menu, the patron may be required to select
either coffee or tea, but not both, as the preferred choice of beverage. This is illustrated in Table 3.3.15.
U
DID YO
?
K NOW
NAND, NOR and XOR mean “not and”, “not or” and “exclusive or” respectively.
Also, the XOR gate can be reconstructed using a combination of only AND,
OR and NOT gates as shown.
A
B A
Q Q
B
61
QUICK 3
C K 3.
CHE
1. State whether each of the statements below is true or false.
a) An OR gate returns an output of 1 when either input is 1.
b) An AND gate returns an output of 1 only when both its inputs are 1.
c) A NOT gate returns an output of 1 when its input is 1.
2. When using a NOR gate, which of the following conditions will return an output of 1?
a) Both inputs are 0
b) Both inputs are 1
c) One input is 1 and the other is 0
d) None of the above
3. When using a NAND gate, which of the following conditions will return an output of 0?
a) Both inputs are 0
b) Both inputs are 1
c) One input is 1 and the other is 0
d) None of the above
4. When using a XOR gate, which of the following conditions will return an output of 1?
a) Both inputs are 0
b) Both inputs are 1
c) One input is 1 and the other is 0
d) None of the above
5. Identify the logic gate described by each of the following truth tables:
a)
Input A Input B Output Q
0 0 0
0 1 1
1 0 1
1 1 1
b)
Input A Input B Output Q
0 0 0
0 1 1
1 0 1
1 1 0
c)
Input A Input B Output Q
0 0 1
0 1 1
1 0 1
1 1 0
62
3.4 Logic Circuits
LEARNING OUTCOMES
1.3.1 Represent logic circuits using either logic circuit diagrams or Boolean statements and
convert between the two representations.
1.3.2 Construct the truth table for a given logic circuit (maximum 3 inputs) and vice versa.
ERMS
Logic gates are the basic building blocks of logic
circuits. A logic circuit can consist of only one logic
gate, but we can build more complex and useful logic
KEY T
circuits by connecting two or more logic gates together. Logic circuit
A logic circuit diagram shows how these logic gates A circuit that consists of only one logic
are connected. A logic circuit diagram is formed by gate or multiple connected logic gates
using symbols to represent logic gates and lines to
represent the wires connecting the inputs and outputs Logic circuit diagram
of the different logic gates together. A visual representation using symbols
to show how the component logic gates
In logic circuit diagrams, lines that cross each other are are connected together in a logic circuit
not connected unless the intersection point is marked
by a solid dot.
intermediate input
input
A D Output
B Q
C
Figure 3.3 Logic circuit with an intermediate input
Within a logic circuit, it is common for the output of a logic gate to be also the input of another logic gate.
In Figure 3.3, the output of the first OR gate is also one of the inputs of the second OR gate. In this textbook,
we will call these “intermediate inputs”.
The logic circuit in Figure 3.3 has three inputs (A, B and C), one intermediate input (D) and one output (Q).
63
3.4.1.2 Constructing Truth Tables from Logic Circuit Diagrams
To generate a truth table from a logic circuit diagram, follow these steps:
1 2 3 4
Determine the total number of Draw the Work out the Work out the
columns and rows in the truth table. truth table intermediate final output.
and fill in all inputs.
Number of columns = total number of the input
inputs, intermediate inputs, and output combinations.
Number of rows = 2n, where n is the
number of inputs.
A D Output
Consider the logic circuit in Figure
3.4. Let us use the steps above to B Q
generate its truth table. C
Determine the total number of columns and rows in the truth table.
Since there are three inputs (A, B and C), one output (Q) and one intermediate input
Step 1: (D):
Draw the truth table and fill in all the input combinations.
Intermediate
Input A Input B Input C Input D Output Q
0 0 0
0 0 1
0 1 0
0 1 1
Step 2:
1 0 0
1 0 1
1 1 0
1 1 1
Table 3.4.1 Filling in all the input combinations in the truth table
64
Work out the intermediate input.
Intermediate
Input A Input B Input C Input D Output Q
0 0 0 0
0 0 1 0
Step 3: 0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Intermediate
Input A Input B Input C Input D Output Q
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
Step 4: 0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
65
3.4.2 Boolean Statements
Like a logic gate, a logic circuit can also be represented by a Boolean statement. Boolean statements are
useful in two ways:
1 They can be evaluated using truth tables to determine the output of a logic circuit.
2 They can determine the arrangement of the logic gates in a logic circuit.
Q=( A• B) +(A•C)
We can evaluate it by expressing all combinations of its inputs and output using a truth table.
Since there are three inputs (A, B and C), one output
Q= ( A• B ) + ( A• C)
(Q) and two intermediate inputs Order 3
(( A•B) and ( A• C)):
Step 1: Figure 3.5 Evaluating a Boolean
Number of columns = total number of inputs, statement following the order of
operations
intermediate inputs, and output = 6
Number of rows = 23 = 8
Using the order of operations, the parts of the Boolean statement in parentheses are to
be evaluated first, followed by the part with the OR operation. This means that “A•B ”
as well as “A •C” are evaluated first, from left to right, since they are contained within
parentheses. They form the two intermediate inputs, D and E.
66
Draw the truth table and fill in all the input combinations.
Intermediate Intermediate
Input A Input B Input C Input D Input E Output Q
(A • B) (A • C)
0 0 0
0 0 1
0 1 0
Step 2:
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Intermediate Intermediate
Input A Input B Input C Input D Input E Output Q
(A • B) (A • C)
0 0 0 0 0
0 0 1 0 0
Step 3:
0 1 0 0 0
0 1 1 0 0
1 0 0 0 0
1 0 1 0 1
1 1 0 1 0
1 1 1 1 1
67
Work out the final output.
Intermediate Intermediate
Input A Input B Input C Input D Input E Output Q
(A • B) (A • C)
0 0 0 0 0 0
0 0 1 0 0 0
Step 4: 0 1 0 0 0 0
0 1 1 0 0 0
1 0 0 0 0 0
1 0 1 0 1 1
1 1 0 1 0 1
1 1 1 1 1 1
1 1 0 1
1 1 1 0
68
Determine the combinations which result in an output of 1.
From the truth table in Table 3.4.8, we can see that there are two combinations which
Step 1: result in output Q = 1:
A = 0, B = 1 and C = 1
A = 1, B = 1 and C = 0
Step 2: Since these conditions need to be all present for output Q to be 1, we should AND them
together. Note that A is used to represent A = 0. This is because when A = 0, Ā will give 1.
A∙B∙C
A∙B∙C
To determine how logic circuits look like, we should use the order Let us draw the logic circuit diagram
of operations to evaluate the Boolean statements. represented by this Boolean
statement:
Recall that in Table 3.4.4, the AND operation is evaluated before the
OR operation. This means that the logic gate representing “A∙ B”
should be drawn first. The output of “A∙B ” is then connected as an Q=A•B+C
input to an OR gate with input C.
A
Step 1:
B
A A∙B
Step 2: B
Figure 3.7 Connecting the output of the AND gate to the OR gate
69
Connect C to the other input of the OR gate.
A A∙B
Step 3: B Q
C
In the previous section, we learnt to draw logic circuit diagrams from Boolean statements. In this section,
we will learn how to do the reverse, which is to derive the Boolean statement from a logic circuit diagram.
Example 1: A D
Let us work out the Boolean statement of the logic
circuit diagram shown in Figure 3.9. B Q
To work out the Boolean statement of a logic C
circuit diagram, we can work backwards from its
final output. Figure 3.9 Deriving the Boolean statement from a
logic circuit diagram
A D
B Q
Step 1:
C
Figure 3.10 Working backwards from the final output
Notice that the intermediate input D is also the output D of an OR gate with inputs A
and B.
A D
Step 2:
B Q
C
Figure 3.11 Working backwards from the intermediate input D
70
Combine the Boolean statements.
Substituting the Boolean statement from Step 2 into the statement from Step 1 will
Step 3: give us the Boolean statement which represents the logic circuit diagram:
Q=(A+B)+C
Example 2: A D
Let us now work out the Boolean statement of the logic
circuit diagram in Figure 3.12. Z
B
Again, we start by working backwards from the final E
output. C
Figure 3.12 Deriving the Boolean statement from a logic
circuit diagram
Notice that the intermediate input D is also the output D of a NOT gate with input A.
D=A Z
B
Next, notice that the intermediate E
C
Step 2: input E is also the output E of an
AND gate with inputs B and C.
Figure 3.14 Working backwards from the
intermediate input D
71
Combine the Boolean statements.
Substituting the Boolean statements from Step 2 into the statement from Step 1 will
Step 2: give us the Boolean statement which represents the logic circuit diagram:
Z=A+(B •C)
QUICK
E CK 3.4
CH
1. Consider the logic circuit below.
A D
B Q
E
C
Figure 3.16 A logic circuit
Q=(A+B)∙C
LEARNING OUTCOMES
1.3.4 Manipulate Boolean statements using the associative and distributive properties of certain
logical operators and De Morgan’s theorem.
Like algebraic expressions, Boolean statements can be manipulated using the associative, distributive and
other properties of the AND, OR and XOR operations. Table 3.5.1 lists some common properties of AND, OR
and XOR for manipulating Boolean statements.
72
Property AND OR XOR
Self-Inverting A A= 0
?
NOT operations gives back the original input:
A=A
KNO W
These properties are
also called “laws” (e.g.,
By using these properties, Boolean statements can be simplified distributive law).
to use fewer logic gates or to prove identities that show two logic
circuits are equivalent.
An alternative and more
As an example of how these properties can be used to prove general way to prove an
an identity, let us try to prove the absorption property of AND, identity is to show that
i.e. A•(A+B)=A. To prove an identity, we start from the Boolean the truth tables for both
statement on one side of the equation and perform manipulations sides match. You can also
step-by-step until it matches the Boolean statement on the other prove that two Boolean
side. In this case, we will start from the left-hand side (LHS) as it has statements are not
more terms for manipulation to reach the right-hand side (RHS): equivalent by comparing
their truth tables and
LHS =A• (A+B) confirming that they do
=( A + 0)• (A+B) (Identity property of OR) not match.
=A +(0• B) (Distributive property of OR)
=A +0 (Annulment property of AND)
=A (Identity property of OR)
=RHS
73
QUICK
E C K 3.5
CH
1. Prove the following identities:
a ) A+ A = 0
b ) (A + B )•B = A•B
c ) (A +B )•(B+ B)= B
d) A =(A+B )•(A+ B)
e ) ( A • B ) ( A•B )=B
LEARNING OUTCOMES
1.3.5 Solve system problems using combinations of logic gates (maximum 3 inputs).
Computing devices and electrical appliances perform logical decisions using logic circuits. This section
introduces three applications of logic circuits that are used to make logical decisions.
In toilets or offices installed with motion-sensing lights, the logic circuit is designed to make a logical
decision of when to switch on the lights depending on the input conditions.
74
One example of a logic circuit used to operate motion-
sensing lights is found in Figure 3.17.
Motion sensor
Motion=1
No motion=0 A
Light bulb
On=1
Light sensor Q Off=0
Bright=1
Dark=0
B C
The motion-sensing light is switched The corresponding Boolean statement for this logic circuit
on when both of its input conditions are is Q=A•B.
fulfilled – its surroundings are dark, and
motion is detected within the toilet or
Input A Input B Intermediate Output Q
office area. At all other times, the light is Input C
switched off. This ensures that the light is
not switched on when no one is around, 0 0 1 0
helping to reduce electricity consumption.
0 1 0 0
When the logic circuit is used to control
a motion-sensing light, inputs A and B 1 0 1 1
are provided by a motion sensor and a
light sensor respectively, and output Q 1 1 0 0
is connected to a light bulb. Table 3.6.2
shows how the truth table should be
interpreted for this circuit. Table 3.6.1 Truth table for Q=A•B
Table 3.6.2 Truth table for the logic circuit of a motion-sensing light
A car door can be unlocked either manually with a key or by receiving an unlock signal via a remote control
sensor. The key switch provides an input of 1 when the key is turned. The remote control switch provides
an input of 1 when the unlock signal is detected.
We can then work out that there are two types of inputs (the key switch and remote control sensor),
resulting in 22 = 4 possible outputs for the lock.
Let us work out the truth table for the car door lock. If we connect inputs A and B to a key switch and remote
control sensor respectively, and the output Q to the lock, we can create the truth table shown in Table 3.6.3.
75
Input A Input B Output Q
Q=A+B
This is equivalent to using a NOR gate.
Hence, the logic circuit for this car door lock can be
designed as follows:
Key switch
Key absent=0
Key present=1 A Lock
Locked=0
Q Unlocked=1
Remote control sensor
Signal absent=0 B
Signal present=1
76
To derive the Boolean statement from a
truth table, recall the following two steps:
Q=A •B+ A •B
Hence, the logic circuit for the two-way
switches can be designed as follows: Figure 3.20 Logic circuit for the two-way switches
QUICK
E C K 3.6
CH
1. A logic circuit is used to determine whether the doors for a shopping mall should be open or closed. The door
should open only during business hours and when it is not raining.
2. A narrow railway crossing is shared by vehicles traveling in two opposite directions, North and South. A warning
light needs to turn on if either a train is approaching or if there is a vehicle waiting to travel North and another
vehicle is waiting to travel South at the same time.
77
QUICK
E C K 3.6
CH
The output to the system is Q for the warning light (0 = off, 1 = on).
W
REVIE
E ST IO N
QU
1. Draw the truth tables for the following Boolean statements.
a) Q=A+(B•C)
b) X=A•B
c) Y=A•B
d) Q=(A+B)•(C+D)
determine its:
a) Boolean statement; and
b) truth table.
4. Draw the truth table for the logic circuit shown below.
B Q
78
ANSWER
2. A
3. B
4. C
5. a) OR b) XOR c) NAND
2. a) Truth table:
Input A Input B Input C Intermediate Input (A) Intermediate Input (A+B) Output Q
0 0 0 1 1 0
0 0 1 1 1 1
0 1 0 1 1 0
0 1 1 1 1 1
1 0 0 0 0 0
1 0 1 0 0 0
1 1 0 0 1 0
1 1 1 0 1 1
b) Logic circuit:
A
B Q
3. a)
Input A Input B Intermediate Input (B) Output Q
0 0 1 1
0 1 0 0
1 0 1 1
1 1 0 1
b)
Input A Input B Intermediate Input (A B) Intermediate Input (A B) Output Q
0 0 0 1 1
0 1 1 0 0
1 0 1 0 1
1 1 0 1 1
79
ANSWER
c)
Input Input Input Intermediate Intermediate Intermediate
Output Q
A B C Input (A•B) Input (B) Input (B•C)
0 0 0 0 1 0 0
0 0 1 0 1 1 1
0 1 0 0 0 0 0
0 1 1 0 0 0 0
1 0 0 0 1 0 0
1 0 1 0 1 1 1
1 1 0 1 0 0 1
1 1 1 1 0 0 1
d)
Input Input Input Intermediate Intermediate
Output Q
A B C Input (B) Input (A•B)
0 0 0 1 0 0
0 0 1 1 0 1
0 1 0 0 0 0
0 1 1 0 0 1
1 0 0 1 1 1
1 0 1 1 1 0
1 1 0 0 0 0
1 1 1 0 0 1
d) RHS =(A+B)•(A+B)
=A+(B•B) (Distributive property of OR)
=A+0 (Complement property of AND)
=A (Identity property of OR)
=LHS
80
ANSWER
81
ANSWER
b) RHS =(A+B)•(A+C)
=(A+B)•A+(A+B)•C (Result from part (a))
=A•A+A•B+A•C+B•C (Result from part (a))
=A+A•B+A•C+B•C (Idempotent property of AND)
=A•(1+B+C)+B•C (Distributive property of AND)
=A•1+B•C (Annulment property of OR)
=A+B•C (Identity property of AND)
= LHS
82
ANSWER
Pg. 77-Quick Check 3.6
1. a)
Input A Input B Output Q
0 0 0
0 1 0
1 0 1
1 1 0
b) Q=A•B
c) A
Q
B
2. a)
Input N Input S Input T Output Q
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
b) Q=N•S+T
Alternatively, using Sum-of-Product (SOP):
Q=N•S•T+N•S•T+N•S•T+N•S•T+N•S•T
c)
N
S Q
T
83
ANSWER
b) X=A•B
Intermediate Intermediate Output Q
Input A Input B
Input (A) Input (B)
0 0 1 1 1
0 1 1 0 0
1 0 0 1 0
1 1 0 0 0
c) Y=A•B
Input A Input B Intermediate Input (B) Output Q
0 0 1 0
0 1 0 0
1 0 1 1
1 1 0 0
84
ANSWER
d) Q=(A+B)•(C+D)
2. a) Boolean statement: Q = A + B
b) Truth table:
Input A Input B Intermediate Input (B) Output Q
0 0 1 1
0 1 0 0
1 0 1 1
1 1 0 1
3. a) A•C•E+A•D•E+B•C•E+B•D•E
b) (A+D)•(A+E)•(B+D)•(B+E)•(C+D)•(C+E)
4. Step 1: Total number of rows in the truth table = 23 = 8 as there are three inputs.
Step 2: Draw the truth table and fill in all the input combinations.
85
ANSWER
A D
B E Q
G
C F
D = A• B
E = B+ C
F =C
G =E • F
Q=D+G
Input Input Input Intermediate
Output Q
A B C Input D Input E Input F Input G
0 0 0 0 0 1 0 0
0 0 1 0 1 0 0 0
0 1 0 0 1 1 1 1
0 1 1 0 1 0 0 0
1 0 0 0 0 1 0 0
1 0 1 0 1 0 0 0
1 1 0 1 1 1 1 1
1 1 1 1 1 0 0 1
86