Sie sind auf Seite 1von 10

Learning objectives

By the end of this chapter you should be able to:


• use logic gate symbols • construct a truth table from :
• understand and define the functions of NOT, AND, OR, • a logic circuit
NAND, NOR and XOR (EOR) gates • a logic expression
• construct the truth table for each of the logic gates above • show understanding that some circuits can be constructed
• construct a logic circuit from : from fewer gates to produce the same outputs.
• a problem statement
• a logic expression
-

Cambridge International AS and A level Computer Science .

4.01 Boolean logic and problem statements


Consider the following question:

Is Colombo further north than Singapore?

In everyday language the answer will be either yes or no. ('Yes', in fact.) However, the question
could be rephrased to make use of the language of Boolean logic:

Colombo is further north than Singapore TRUE or FALSE?

More formally, the statement:

Colombo is further north than Singapore.

can be described as an example of a logic assertion or a logic proposition that can have
only one of the two alternative Boolean logic values TRUE or FALSE.

Logic proposition: a statement that is either TRUE or FALSE

Now consider the following two individual statements:

• You should take an umbrella if it is raining or if the weather forecast is for rain later.
• The air-conditioning system is set to come on in an office only during working hours but
also only if the temperature rises to above 25°C.
Each of these statements contains two logic propositions which are highlighted. In each
statement these logic propositions are combined in some way. Finally, each statement has
the addition of an outcome which is dependent on the combination of the two propositions.
Each of these is, therefore, an individual example of a problem statement.

Problem statement: an informal definition of an outcome which is dependent on one logic


proposition or a combination of two or more logic propositions

4.02 Boolean operators


The problem statements identified above can be more formally expressed in a form that is
suitable for hand ling with Boolean logic. To do this it is necessary to use Boolean operators.
The three basic Boolean operators are AND, OR and NOT.

The definition for AND can be expressed as:

AAND Bis TRUE if A is TRUE and Bis TRUE

Here, both A and B represent any logic proposition or assertion that has a value TRUE or
FALSE.

In a similar way the definition for OR is:

A ORB is TRUE if A is TRUE or Bis TRUE

The two problem statements above might be rephrased as follows:

• Take_umbrella = TRUE IF (raining= TRUE) OR (rain_forecast = TRUE)


• System_on = TRUE IF (office hours= TRUE) AND (temperature> 25°()
}· ," ::: ,·, , Chapter 4: Logic Gates and Logic Circuits -

Each original problem statement has now been rep hrased as a form of logic expression
with a defined outcome. The format of each expression here does not fol low any fo rma lly
defined convention but the structu re does allow the underlying logic to be understood. In
genera l, a logic expression consists of logic propositions combi ned using Boolean operators
and the expression optionally may be stated with a defined output.

Logic expression: logic propositions combined using Boolean operators, which may be written with a
defined outcome

TASK4.0l
Convert the following problem statement into a simple logic expression:
A document can only be copied if it is not covered by copyright or if there is copyright and
permission has been obtained.

Any logic expression can be constructed using only the Boolean ope rators AN D, OR and NOT
bu t it is often conven ient to use other operators. Here are the definitions for t he six operators
wit h which you need to be fa mil iar:
NOT A is TRU E if A is FALSE


• A AND B is TRUE if A is TRU E and B is TRUE
• A ORB is TRUE if A is TRUE or B is TRUE
• A NAND Bis TRU E if A is FALSE or B is FALSE
• A NOR B is TRU E if A is FALSE and B is FALSE
• A XOR Bis TRUE if A is TRUE or B is tr ue but not both of them

4.03 Truth tables


The trut h table is a simple but powerfu l technique for representing any logic expression or fo r
describing t he possible output s from a logic circu it.
A t ruth ta ble is presented by making use of the co nvention that TRUE ca n be
represented as 1 and FALS E can be represe nted as 0. The simplest use of a t rut h table is
A B X
to rep resent the logic associated with a Boolean operator.
0 0 0
As an example let us consider the AN D operator. The labelli ng of the truth table follows
0 l 0
the convention that the initially defined values are represented by A and Band the va lue
obtained from the simple expression using the AND operator is represented by X. In oth er l 0 0
words we write the truth table fo r X= AAND B. Rememberi ng that AND only returns tru e if l 1 1
both A and Bare true we expect a truth table with only one instance of X having the value 1.
The truth table is shown in Table 4.01. Table 4.01 The truth table for
the AND operator
The tru t h table has four rows corresponding to t he fo ur com binations of th e t ruth val ues
for A and B. Three of t hese lead to a O in t he X column as expected.

TASK4.02
Without looking further on in the chapter, construct the truth table fo r the OR operator.
~

Cambridge International AS and A level Computer Science ,~

4.04 Logic circuits and logic gates


The d igita I circuits that constitute the inner work ings of a co m puter system aII operate on the
basis that at any one t ime an individual part of the circu it is eit her in an 'on' state, which can
be represe nted by a 1, or in an 'off' state, represented by a 0. The phys ical circuit ry consists of
integrated circui ts constructed from t ransistors. There can be billions of tra nsistors in a single
integrated ci rcu it.

We wil l view a logic circuit as comprising component parts cal led logic gates. Each diffe rent
logic gate has an operation that matches a Boolean operator.

Logic gate: a component of a logic circu it that has an operation match ing that of a Boolean operato r

Discussion Point:
There will be no further discussion of integrated circuits in this book but you might wish
to do some research and have a look at the structure of a small-scale integration chip.

When drawing a circuit, st andard symbols are used for the logic gates. As an example,
the sy mbol shown in Figu re 4.01 represents an AND gate.
Fi gu re 4.01 The symbol fo r
The fi rst po int to note here is that the shape defines the type of gate. The second point the AND logic gate
is that the inpu ts are on t he left-han d side and the output is on the right- hand side. In
general, the number of inputs is not limited to two bu t t he discussion in t his book w ill only
co nsider circuits where the number of inputs does not exceed two.

Figure 4.02 shows t he logic gate sym bols and the associated truth tab les for each of th e six
Boolean operato rs introduced in Section 4.02.

NOT

A B X

AND =D-- 0
0
1
0
1
0
0
0
0
1 1 1

A B X

OR -D- 0
0
1
0
1
0
0
1
1
1 1 1

A B X

NAN O ==[y-- 0
0
1
0
1
0
1
1
1
1 1 0
I
I .
~
0
· 'ii·, ,i Chapter 4: Logic Gates and Logic Circuits

A B X
0 0 1
NOR 0 1 0
1 0 0
1 1 0

A B X
0 0 0
XOR 0 1 1
1 0 1
1 1 0

Figure 4.02 Logic gate symbols and their associated truth tables

There are two other points to note here. The NOT gate is a special case having only one
input. The NAND and NOR gates are each a combination of a gate and the NOT gate so they
produce complementary output to that produced by the AND and OR gates.

TASK4.03
Draw a circuit where A and Bare input to an AND gate from which the output is carried to a
NOT gate from which there is an output X. Show that this has the same outcome as having one
NANO gate.

Extension question 4.01


Could the same outcome be produced by positioning a NOT gate before the AND gate?

You need to remember the symbol for each of these gates. A good start here is to remember
that AN D has the proper D symbo l and OR has the curvy one. You also need to remember the

definitions for the gates so that you can construct the co rresponding truth table for each gate.

Question 4.01
Can you recall from memory the symbols and definitions of the six logic gates introduced in
this chapter?

WORKED EXAMPLE 4.01

Constructing a logic circuit from a problem statement or logic expression


You need to be able to construct a logic circuit from eithe r a problem statement or from
a logic expression. If you are given a problem statement the best approach is to first
convert it to a logic expression and then to identify t he individual Boolean operations in
the logic expression. This approach wil l be illustrated here.

Consider th e following problem statement: A bank offers a spec ial lending rate to
customers subject to certain conditions. To qualify, a customer must satisfy certain criteria:

• The customer has been w ith the bank for two yea rs.
• Two of the following conditions must also apply:
• The customer is married.
• The customer is aged 25 years or older.
• The customer's parents are customers of the bank.

- ------
...
Cambridge International AS and A level Computer Science ··

To convert this statement to a logic expression you need to represent each condition by
a symbo l (in the same way that a prob lem might be tackled in normal algebra):

• Let A represent an account held for two years .


• Let B represent that the customer is married.
• Let C represent that the customer's is age 25 years or more.
• Let D represent th at the customer's parents have an account.
The logic expression can then be written as:

AAND (((BA ND C) OR (BAND D)) OR (C AND D))

This cou ld alternative ly be presented with an outcome:

Special_rate IF AAND (((BAND C) OR (BAND D)) OR (C AN D D))

Note the use of brackets to ensure that the meaning is clear. You may think t hat not all of
the brackets are needed. In this example, an extra pair has been in~luded to guide the
construction of the circuit where only two inputs are allowed for any of the gates.

It can be seen, therefore, that the logic circuit corresponding to this logic expression
derived from the original problem statement could be constructed usin g four AND gates
and t wo OR gates as shown in Figure 4.03.

A---------------

B
X

Figure 4.03 A logic circuit constructed from a problem statement

WORKED EXAMPLE 4,02

Constructing a truth table from a logic expression or logic circuit


Yo u also need to be able to construct a truth table from either a logic express ion or a
logic circuit. We might have continued with th e problem in Worked Example 4.01 but
four inputs wi ll lead to 16 rows in the truth table. Instead, we consider a sl ightly simp ler
problem with only three inputs and therefore only eight rows in the truth table . We will
start wi th the circu it shown in Figure 4.04.

C ---------'
Figure 4.04 A circuit with three inputs for conversion to a truth table
( - -

· Chapter 4: Logic Gates and Logic Circuits

Tab le 4.02 shows how the truth table needs to be set up initially. There are several points
to note here. The first is that you must take care to include all of the eight different possible
com binations of the input va lues. Therefore, you present the va lu es in increasing binary
number va lue from 000 to 111. The secon d point is that for such a circuit it is not sensible to
try to work out the outputs directly from the input values. Instead a systemat ic approach
should be used. This involves identifying intermediate points in the circuit and recording
the values at each of them in the columns headed 'Workspace' in Tab le 4.02.

Inputs Workspace 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
Table 4.02 The initial empty truth table

Figu re 4.05 shows the same circu it but w ith four intermed iate points labelled M, N, P and


Q identified. Each one has been inserted on the output side of a logic gate.
p

X
B -------1
C ----------'
Figu re 4.05 The circuit in Figure 4.04 with intermediate points identified

Now you need to work systematica lly through the intermed iate points. You start by
filling in the co lumns for Mand N. Then you fill in the colu mn s for P and Qw hich feed
into th e fi nal AND gate. The fina l truth tab le is shown as Table 4.03. The circuit has two
co mbi nations of input s that lead to a TRUE output from the circu it.

The columns contain ing th e intermediate va lues (the workspace) could be deleted at this stage.

Inputs Workspace Output


A B C M N p Q X
0 0 0 0 1 1 0 0
0 0 1 0 1 1 1 1
0 1 0 0 0 1 0 0
0 1 1 0 0 1 0 0
1 0 0 0 1 1 0 0
1 0 1 0 1 1 1 1
1 1 0 1 0 0 0 0
1 1 1 1 0 0 0 0
Table 4.03 The truth table fo r the circu it shown in Figure 4.05
-
Cambridge International AS and A level Computer Science

One fina l point t o make here is that you may be able to check part of your fina l solution
by looking at just part of the circuit. For this example, if you look at the circuit you
w ill see that the path from input C to the output passes through two AND gates. It
follows, therefore, that for all combinations with C having value Othe output must be 0.
Therefore, in order to check your final so lution you on ly need to exam ine the other four
combinations of input values where Chas va lue 1.

TASK4.04
An oven has a number of components which should all be working properly. For each
component there is a signalling mechanism that informs a management system if all is well
or if there is a problem when the oven is being used. Table 4.04 summarises t he signa l values
that reco rd the status for each component.

Signal Value Component condition


0 Fan not working
A
1 Fan working properly
0 Internal light not working
B
1 Internal light working properly
0 Th ermometer reading too high
C
1 Thermometer reading in range

Table 4.04 Signals from the oven components

If the thermometer reading is in range but either or both the fan and light are not working, the
management system has to output a signal to activate a warning light on the control panel.
Draw a logic circuit for this fault condition .

4.05 Alternative circuits


For any given logic problem there will be different circu its that deliver the same output values
from a given set of inputs. In so me cases it will be possible to simplify an initial circuit design
by reducing the number of logic gates. As a trivial example you may have noticed that the
circuit in Figure 4.04 includes an AND gate immediately followed by a NOT gate. Th ese cou ld
have been combined as a NANO gate. For more comp lex examples, there are techniques
available which will be discussed in Chapter 18 (Sections 18.03 and 18.04).
However, reducing complexity is not just about reduc in g the number
of logic gates. Logic circuit manufact urers can reduce costs by building
circuits that contain only one type of logic gate; one that is itself cheap
to manufacture. The NANO gate is an example of a universal gate wh ich
X
fits th is re quirement (the NOR gate is the other possibil ity). Manufacturers
may find it cheaper to build a circuit with j ust NANO gates even though the
circuit contains more components than alternatives contain ing diffe rent
gates. To illustrate the concept of t he un iversa l NANO gate the circu it in Figure 4.06 A circuit containing only NANO
Fi gure 4.06 has the same functionality as an OR gate. gates which is equivalent to an OR gate

Extension question 4.02


Create the truth table for the circuit shown in Figure 4.06 and show that it is the same as that
for an OR gate.
I ~ ~1 '" ~ Chapter 4: Logic Gates and Logic Circuits '

• A logic scenario can be described by a problem statement or a logic expression .

• A logic expression comprises logic propositions and Boolean operators.

• Logic circuits are constructed from logic gates.

• The operation of a logic gate matches that of a Boolean operator.

• The outcome of a logic expression or a logic circuit can be expressed as a truth table.

Exam-style Questions
1 a The followi ng are t he symbo ls fo r t hree different logic gates.

Gate 1 Gate 2 Gate 3

-{>-
Identify each of the logic gates . [3]
ii Draw the trut h table fo r eithe r Gate 1 or Gate 2. [2]


b Consider t he fo llowing circ uit:

I
I

(
Const ruct the trut h tab le fo r t he circu it using t he fo llowing tem plate:

A
0
Inputs
B
0
C
0
Workspace Output
X

0 0 l

0 l 0

t 0 l l

l 0 0

l 0 l

l l 0

l l l

[8]

ii There is an eleme nt of redun dancy in th is diagram. Explain what t he proble m is. [2]
- - --- -- - - --- -- -

Cambridge International AS and A level Computer Science

2 a The definition of the NAND gate can be expressed as:

ANAND Bis TRUE if A is FALSE or Bis FALSE

Draw the truth tab le fo r a NAND gate [4]

b Consider the following statement:

In a competition, two teams play two matches aga inst each other. One of the teams is declared the winner
if one of the follow ing results occurs:
The team wins both matches.

Th e team wins one match and loses the ot her but has the hi ghest tota l sco re.

Identify the three logic propositions in t hi s statement. [3]

ii By assigning the symbols A, Band C to th ese three propositions express th e outcome of the competition
as a logic expression. [3]

iii Construct a logic circui t to match this logic expression. [4]

3 A domestic heating system has a hot water tank and a number of radiato rs. Th ere is a computerised management
system which re ce ives signals dependent o n whet her or not the conditions for components are as they should be.
Th e fo llowing table summarises the signals received :

Signal Value Component condition


0 Wate r flow in the radiators is too low
A
1 Wat er flow in the rad iat ors is within limits
0 Hot wa t er tank t emperature too high
B
1 Hot wa ter tank temperature w ithi n limits
0 Wate r level in hot wa ter tank too low
C
1 Wate r level in hot water tank w ithin limits

a Consider the fo llowing fault co ndition . The water level in the hot wat er tank is too low and t he temperature
in the hot wate r tank is too high . The management system must outp ut a signal to switch off the system .

Const ruct a t ru th t able for th is fault condi ti on includin g the A, Ba nd C signals. [4]

ii Construct the circuit diagram forth is fau lt co ndit ion to match this t ruth table. [5]

b Consi der the fault co ndit ion where the hot wate r tank tem perature is with in limits but t he water flow in the
radiato rs is too low and the water level in the hot wate r t an k is too low. Co nstruct the circuit diagram for this fault
condition whi ch requires t he management system to output a signal to increase wa ter pressu re. [5]

Das könnte Ihnen auch gefallen