Download as pdf or txt
Download as pdf or txt
You are on page 1of 178

Processing

and Logic Concepts


MLPL181-01
Processing and Logic Concepts
MLPL181-01

Compiled by: Marie Murphy, Ana Ribiero, Warwick Ashford, Louise Lok,
Stephen van Rensburg

Updated by: Angelique Kolle, Carla Labuschagne, Lance Whyte, Cedric


Maenetja, Deerasha Marriemuthu and Sheunesu Makura

Quality assured by: Francois du Toit

Edited by: Jeremy David

Version 1.1

© March 2018 CTI Education Group


Table of Contents
Introduction 1
About this module 1
Prerequisites 1
Assessment for pass 1
Reference books 2
How to approach this module 3
Software requirements 3
Other requirements 4
Symbols used in this learning manual 4
Unit 1 - Number Systems 5
1.1 Converting number systems 5
1.1.1 Converting from one number system to another 5
1.1.2 Converting from base 10 5
1.1.3 Converting to base 10 9
1.1.4 Shortcut notation 13
1.2 Addition and subtraction 17
1.2.1 Arithmetic 17
1.2.2 Addition 17
1.2.3 Subtraction 24
1.3 Complements and overflows 27
1.3.2 Complement arithmetic 28
1.3.3 Overflow 31
1.3.4 Complements and overflows - summary 31
1.4 Key terms 32
1.5 Exercises 32
1.6 Revision questions 34
Unit 2 - Logic Gates and Truth Tables 37
2.1 Introduction to logic concepts 37
2.2 Logic symbols and logic gates 37
2.2.1 Binary logic 37
2.2.2 Binary operators 39
2.2.3 Logic gates: AND, OR, NOT 41
2.2.4 Additional logic gates 45
2.2.5 Truth table examples 49
2.3 Key terms 50
2.4 Exercises 51
2.5 Revision questions 52
Unit 3 - Converting Boolean Algebra 54
3.1 Introduction to Boolean algebra 54
3.2 Characteristics 54
3.3 Boolean algebra: symbols and conversions 55
3.4 Development of equations from logical diagrams 56
3.4.1 First level logic 56
3.4.2 Second level logic 56
3.4.3 Third level logic 57
3.4.4 Fourth level logic 58
3.4.5 The law of NOT 59
3.4.6 Logic diagram with state indicators 60
3.4.7 State indicators on outputs 60
3.4.8 Converting logic diagrams to Boolean equations 62
3.4.9 Converting Boolean equations to logic diagrams 63
3.5 Key terms 66
3.6 Exercises 66
3.7 Revision questions 70
Unit 4 - Using Boolean Algebra 71
4.1 Boolean algebra: laws and theorems 71
4.1.1 Boolean functions 75
4.2 De Morgan's theorem 75
4.3 Key terms 80
4.4 Exercises 80
4.5 Revision questions 81
Unit 5 - The Karnaugh Map 82
5.1 Introduction to the Karnaugh map 82
5.2 Basic shapes of the Karnaugh map 84
5.2.1 The one-variable Karnaugh map 87
5.2.2 The two-variable Karnaugh map 88
5.2.3 The three-variable Karnaugh map 89
5.2.4 The four-variable Karnaugh map 92
5.3 Key terms 96
5.4 Exercises 96
5.5 Revision questions 96
Unit 6 - Decision Tables 97
6.1 The elements of decision tables 97
6.1.1 Decision table example 97
6.2 Constructing decision tables 99
6.3 Summary 101
6.4 Determining 'Impossibles' on a decision table 102
6.5 Decision table practical examples 102
6.5.1 Example one 102
6.5.2 Example two 103
6.5.3 Example three 104
6.6 Key terms 104
6.7 Exercises 105
6.8 Revision questions 106
Unit 7 - System Flowcharts 108
7.1 Introduction 108
7.2 System flowchart symbols 108
7.3 System flowchart tips 113
7.4 Reading a system flowchart 113
7.4.1 Activity Instructions 113
7.4.2 Activity Instructions 115
7.5 Key terms 116
7.6 Exercises 116
7.7 Revision questions 118
Unit 8 - Program Flowcharts 120
8.1 Program flowchart 120
8.2 Program flowchart symbols 120
8.3 Variables 122
8.4 Calculations 122
8.5 Simple flowcharts 122
8.6 Flowchart loops 123
8.6.1 Flowchart loop example 124
8.6.2 for loops 125
8.7 Logical decisions 127
8.7.1 Determining logical decisions 127
8.7.2 Illustrating logical decisions 127
8.8 Accumulating and incrementing totals 127
8.8.1 Accumulating totals – example 1 128
8.8.2 Incrementing totals – example 2 129
8.9 Printed output 130
8.9.1 Printed output – example 1 131
8.9.2 Printed output – example 2 131
8.10 Error checking 132
8.10.1 Error checking example 132
8.11 Key terms 133
8.12 Exercises 134
8.13 Revision questions 137
Unit 9 - Trace tables 140
9.1 Introduction to trace tables 140
9.2 A trace table construction 140
9.3 Trace table example 141
9.4 Key terms 143
9.5 Exercises 143
9.6 Revision questions 147
Test Your Knowledge 150
Truth tables 150
Logic diagrams to and from expressions or equations 151
Boolean algebra 153
De Morgan's theorem 154
Karnaugh maps 155
Decision tables 156
System flowcharts 158
Program flowcharts 160
Trace tables 162
Examination Requirements 167
References 168
Processing and Logic Concepts – Exercise Checklist 169
Evaluation Form 170
Introduction

About this module

This module lays the foundation for understanding the logic concepts on which
computer programming is based. The module concentrates on three key areas
in particular, namely: number systems, logic concepts and algorithm design.

The first section introduces students to different number systems where they
apply their knowledge to convert from one number system to another and
perform basic addition and subtraction in different number systems. The
execution of arithmetic operations in a computer is discussed.

Logic concepts covers logic symbols AND, OR and NOT. It covers electronic
circuits containing logic gates and the representation of logical equations as
truth tables. Boolean algebra and Karnaugh maps are used for proving and
simplifying Boolean expressions. The student is taught to apply decision tables
as a tool to model and test complex logic.

The third section covers system and program flowcharts and the application of
trace tables to discover logical errors in program flowcharts. The standard
symbols used for flowcharting will be illustrated and students will write their
first algorithms and test the validity of their designs.

Prerequisites
The Processing and Logic Concepts module requires basic mathematics-
arithmetic and algebra to Grade 9 level.

Assessment for pass

A pass is awarded for the module on achievement of at least 60% in the


module examination.

Table 1 – LOs and ACs


Learning Outcome Assessment Criteria
1.1 Convert a number from decimal
to any base, but specifically binary,
octal or hexadecimal.
1. Manipulation of quantities in 1.2 Convert a number from any base,
different number systems. but specifically binary, octal or
hexadecimal, to decimal.
1.3 Perform addition and subtraction
in binary, octal and hexadecimal.
2.1 Illustrate Boolean expressions as
2. Evaluate expressions (or circuits.
scenarios) that involve logical 2.2 Simplify Boolean expressions.
operators. 2.3 Prove Boolean equations true or
false.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 1 of 170
2.4 Determine the result of a Boolean
expression for a set of variable
values.
2.5 Determine conditions, actions and
impossible condition states for a
given scenario.
2.6 Determine the actions to take
place for a particular set of conditions
within a given scenario.
3.1 Use appropriate symbols for the
components of the construct.
3.2 Plot the direction of information
flow for a given scenario.
3.3 Interpret a given system
flowchart.
3. Represent logic high-level and low- 3.4 Use Boolean logic to control flow.
level procedural constructs. 3.5 Apply iteration
3.6 Perform increments to count
inputs (counting).
3.7 Perform accumulation on inputs
(summing).
3.8 Validate input and display error
messages.
4.1 Draw a trace table for a program
flowchart.
4.2 Use sample input to trace
through the logic of a program
4. Evaluate a program to determine flowchart.
correctness. 4.3 Determine errors in initialisation,
accumulation, increment and
validation.
4.4 Determine semantic errors in an
algorithm.

Reference books

 There is no required textbook for this module.

Supplementary reference books that may be borrowed from the


library for further understanding include:

 Sprankle, M. & Hubbard, J. 2012. Problem solving and


programming concepts. 9th edition. New Jersey: Prentice Hall.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 2 of 170
How to approach this module

Ensure that you know and understand the unit before continuing with an
exercise. Work through the examples and complete all the exercises before
attempting the examination.

You will not pass the examination if you rush through the material without
completing the exercises and revision questions and checking them with
your lecturer. The examinations are designed to test theory, insight and
practical skills. The examination will consist of multiple choice questions and
written questions.

It is very important that you use all of the study aids available to you. Some of
the questions in the examinations will test your general knowledge on
advanced subjects that may not have been covered in the learning manual,
although the content in the learning manual will be sufficient to ensure that
you pass.

Take note that each module builds on previous modules. Examinations will
cover all the material with which you should be familiar. You may be asked to
apply the skills you learn in this module (and the other fundamental modules)
to questions in your programming language examinations, so mastery of this
material is essential.

You have a certain number of days to complete the module, including the
examination.

Use Table 2 as a guideline of how to structure your time.

Table 2 - Module breakdown


Section Unit Days % Notes
Number systems 1 1
Logic gates 2 1
Truth Tables 2 1
Boolean Algebra 3,4 1
Karnaugh Map 5 1
Decision Tables 6 2
System Flowcharts 7 2
Program Flowcharts and
8,9 3
Trace Tables
Preparation and Assessment covering all
3 100
Examination module content.
Total 15

Software requirements
The Raptor flowcharting program available from
http://raptor.martincarlisle.com/

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 3 of 170
Other requirements
A flowchart stencil.

Symbols used in this learning manual

Denotes the start of a unit in the learning manual.

Denotes the outcomes of the unit, i.e. the knowledge and skills
that you should have acquired after each section.

Denotes the start of a sub-section in the learning manual.

Points out the keywords of each section. Ensure that you can
name and explain all the keywords before proceeding to the
next section.

Test your understanding. Answers to these revision questions


are provided in the lecturer guide.

Exercises for each section

This icon is used to indicate supplementary reading from other


sources that you can use to broaden your knowledge.

Denotes a bibliography

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 4 of 170
Unit 1 - Number Systems

At the end of this unit you will be able to:

 Convert a given number from one number system to another.


 Perform basic addition and subtraction on sets of numbers.
 Understand how a computer performs arithmetic.
 Grasp the concept of one's and two's complement.
 Understand overflow.

1.1 Converting number systems

1.1.1 Converting from one number system to another


The most commonly used number system is the decimal number system. This
makes it the most meaningful, but it is important to realise that any whole
number value can be represented in any number system.

When visiting foreign countries, most travellers must convert the prices of
goods and services from the foreign currency to their own currency before they
can judge the cost of the goods or services. A similar situation exists for
programmers because most input and final output values will be in decimal,
but computers work with only binary, octal and hexadecimal values. Therefore,
decimals are constantly converted to numbers expressed in these number
systems and vice versa.

There are also conditions that make it convenient to convert from a decimal
system to some other number system. There are many methods or techniques
that can be used to convert numbers from one base to another. This unit
illustrates one technique used in converting from any base to base 10 and a
second technique to be used in converting from base 10 to any other base.

1.1.2 Converting from base 10


At times, a computer programmer will need to convert a decimal number to a
binary, octal, or hexadecimal. The following technique will convert any decimal
value to any other base. It is usually called the division remainder
technique. There are four steps in the division-remainder technique.

 Step 1: Divide the decimal number to be converted by the value of the


new base. For example, to convert to binary, divide by two.
 Step 2: Record the remainder from Step 1 as the rightmost digit of the
new base number.
 Step 3: Divide the answer of the previous division by the new base.
 Step 4: Record the remainder from Step 3 as the next digit (to the left)
of the new base number.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 5 of 170
NOTE Steps 3 and 4 must be repeated, recording remainders from right to
left, until getting an answer of zero in Step 3. Do not forget to record
the remainder when the division answer is equal to zero.

1.1.2.1 Decimal to binary


Figure 1.1 illustrates the steps for converting the decimal number 26 to its
binary equivalent. In this example, five division cycles are required. When the
last division result is an answer of zero and the remainder is recorded, 11010
is derived as the binary equivalent of decimal 26.

2610 = ?2

2 26 Step 1: Divide by the Step 2: Record the remainder


new base. from Step 1 as the rightmost digit
of the new base number.
13 r 0 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
26/2=13 repeat Steps 3 and 4.
remainder is 0
6 r 1 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
13/2=6 repeat Steps 3 and 4.
remainder is 1.
3 r 0 Step 3: Divide answer of Step 4: Record the remainder as
previous division by the the next digit; if the answer to
new base division is zero, stop; otherwise
6/2=3 repeat Steps 3 and 4.
remainder is 0
1 r 1 Step 3: Divide answer of Step 4: Record the remainder as
previous division by the the next digit; if answer to
new base. division is zero, stop; otherwise
3/2=1. repeat Steps 3 and 4.
remainder is 1
0 r 1 1/2=0 remainder is 1
The answer to the division is zero, so stop. Read the
converted number upwards.

2610=110102

Figure 1.1 – Decimal-to-binary conversion

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 6 of 170
1.1.2.2 Decimal to octal

41610 = ?8

8 416 Step 1: Divide by the Step 2: Record the remainder


new base. from Step 1 as the rightmost digit
of the new base number.
52 r 0 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
416/8=52 repeat Steps 3 and 4.
remainder is 0
6 r 4 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
52/8=6 repeat Steps 3 and 4.
remainder is 4.
0 r 6 6/8=0 remainder is 6
The answer to the division is zero, so stop. Read the
converted number upwards.

41610 = 6408

Figure 1.2 shows the steps required to convert decimal 416 to its octal
equivalent of 640. The example requires repetition of Step 3 and 4 to
determine that decimal 416 is equivalent to octal 640.

41610 = ?8

8 416 Step 1: Divide by the Step 2: Record the remainder


new base. from Step 1 as the rightmost digit
of the new base number.
52 r 0 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
416/8=52 repeat Steps 3 and 4.
remainder is 0
6 r 4 Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
52/8=6 repeat Steps 3 and 4.
remainder is 4.
0 r 6 6/8=0 remainder is 6
The answer to the division is zero, so stop. Read the
converted number upwards.

41610 = 6408

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 7 of 170
Figure 1.2 – Decimal-to-octal conversion

1.1.2.3 Decimal to hexadecimal


If a remainder of 10 to 15 results when converting to hexadecimal, the
remainder must be converted to a hexadecimal digit of A to F as shown in
Table 3. Figure 1.3 shows the steps required to convert decimal 941 to its
equivalent hexadecimal value. Dividing by 16 in the first step results in a
remainder of 13. This decimal value must be converted to its hexadecimal
equivalent of D. The example requires repetition of Steps 3 and 4 to determine
that decimal 941 is equivalent to hexadecimal 3AD.

Table 3 - Decimal and Hexadecimal equivalents


DECIMAL HEXADECIMAL
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 A
11 B
12 C
13 D
14 E
15 F

Figure 1.3 shows how to convert from decimal to hexadecimal:

94110 = ?16

16 941 Step 1: Divide by the Step 2: Record the remainder


new base. from Step 1 as the rightmost
digit of the new base number.
58 r 13 = D Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
941/16=58 repeat Steps 3 and 4.
remainder is 13
3 r 10 = A Step 3: Divide the Step 4: Record the remainder as
answer of previous the next digit; if answer to
division by the new base. division is zero, stop; otherwise
58/16=3 repeat Steps 3 and 4.
remainder is 10.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 8 of 170
0 r 3 3/16=0 remainder is 3
The answer to the division is zero, so stop. Read the
converted number upwards.

94110 = 3AD16

Figure 1.3 – Converting from decimal to hexadecimal

1.1.3 Converting to base 10


When converting numbers to decimal values, column or place values must be
determined. Table 4 illustrates the general rule for determining column values
and the specifics for base 16, base 10, base 8, and base 2.

The general rule for determining column values is that the first (or right-hand)
whole number column value is equal to the value of the base to the zero
power. Any number to the power of zero is equal to one. Therefore, all bases
have a column value of one for the first column.
The second column is equal to the value of the base to the first power. The
value of any number to the first power is equal to that same number.
Therefore, the second column value in all number systems is equal to the value
of the base.

The third column value is equal to the base to the second power, or the base
value times itself. The values of the columns continue to increase in value by
one more power for each column from right to left. For example, the fourth
column value is the base to the third power; the fifth column value is the base
to the fourth power, and so on.

The equivalent decimal value for bases 16, 10, 8, and 2 is shown in the
following table.

Table 4 – Converting to base 10

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 9 of 170
The easiest way to understand how column values are determined is to look at
the familiar base of 10. The first column value is equal to 10 to the zero power,
which is one. The second column value is 10 to the first power, which is 10.
The third column value is 10 to the second power, which is 100 (10 x 10). The
fourth column value is 10 to the third power, which is 1 000 (10 x 10 x 10).
The fifth column value is 10 to the fourth power, which is 10 000 (10 x 10 x 10
x 10). This same process can be used for determining the column value for
base 2, base 8, base 16, or any other base.

NOTE When applying the method above, the resulting column values are
decimal, and not in the original base.

A short method of determining the column values is to remember that the first
or right-hand column value is always going to be 1. The second column value
is always equal to the base. From the third column onwards, the column value
is equal to the base multiplied by the column value to its right. For example,
the fourth column value in base 16 is equal to the base multiplied by the
column value to its right. In other words: 16 x 256 = 4 096.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 10 of 170
There are three steps in converting a number in any number system to its
decimal equivalent:

 Step 1: Determine the column value of each digit (in decimal).


 Step 2: Multiply the column value by the digit in the column. Repeat this
step for each digit of the number to be converted.
 Step 3: Sum the products calculated in Step 2. The total is the
equivalent value in decimal.

1.1.3.1 Binary to decimal


Figure 1.4 shows the three steps used to convert the binary number 10110 to
its equivalent decimal. Notice that the column values double because the base
is two. The total in this example is equal to 22. Therefore, binary 10110 is
equal to decimal 22.

101102 = ?10

 Step 1: Determine column values

24 23 22 21 20
16s 8s 4s 2s 1s
1 0 1 1 0

 Step 2: Multiply column values by column digits

16s 8s 4s 2s 1s
x1 x0 x1 x1 x0
16 0 4 2 0

 Step 3: Sum the products

16 + 0 + 4 + 2 + 0 = 22

101102 = 2210

Figure 1.4 – Converting from binary to decimal

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 11 of 170
1.1.3.2 Octal to decimal
Figure 1.5 illustrates the steps required to convert octal 257 to its equivalent
decimal value. The total in this example is equal to 175. Therefore, octal 257 is
equal to decimal 175.

2578 = ?10

 Step 1: Determine column values

82 81 80
64s 8s 1s
2 5 7

 Step 2: Multiply column values by column digits

64s 8s 1s
x2 x5 x7
128 40 7

 Step 3: Sum the products

128 + 40 + 7 = 175

2578 = 17510

Figure 1.5 – Converting from octal to decimal

1.1.3.3 Hexadecimal to decimal

Figure 1.6 shows the steps required to convert hexadecimal 2B3C to its
equivalent decimal value. Notice that the hexadecimal digits of A to F must be
converted to their equivalent decimal value of 10 to 15 before multiplying.
In this case, B is equal to 11 and C is equal to 12. The sum of the products in
this example is 11068. Therefore, 11068 is the decimal equivalent of
hexadecimal 2B3C.

2B3C16 = ?10

 Step 1: Determine column values

163 162 161 160


4096s 256s 16s 1s
2 B 3 C

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 12 of 170
 Step 2: Multiply column values by column digits

B=11
C=12

4096s 256s 16s 1s


x2 x11 x3 x12
8192 2816 48 12

 Step 3: Sum the products

8192
2816
48
+ 12
11068

2B3C16 = 1106810

Figure 1.6 – Converting hexadecimal to decimal

1.1.4 Shortcut notation


It is very useful to have a shortcut notation for binary numbers when printing
out the contents of memory. If the contents of memory were to be printed in
binary, several pages of zeros and ones would be required. This form is very
difficult to use for a memory dump, because of the length of the output and
the narrow choice of characters.

To reduce the volume and print time of the memory dump and to show
memory content with a greater variety of symbols, either the octal or
hexadecimal number system is used as a shortcut notation. All computers use
either octal or hexadecimal as their shortcut notation, depending on the
memory organisation of the machine. If the basic unit of storage (such as a
byte) is a multiple of three bits, octal is used as the shortcut. If the basic unit
of storage is a multiple of four bits, hexadecimal is used as the shortcut
notation. Because the selection of the shortcut notation is determined by the
memory organisation of the machine, any particular computer will always use
either octal or hexadecimal, but not both. Therefore, programmers are not
required to convert between octal and hexadecimal.

Table 5 shows the relationship of octal and hexadecimal to binary. First, note
that the maximum value for a single digit of octal (octal 7) is equal to the
maximum value of three digits of binary.

The value range of one digit of octal duplicates the value range of three digits
of binary. If octal digits are substituted for binary digits, the substitution is on
a one-to-three basis. Computers using octal as the shortcut notation can
represent the binary contents of memory in one third of the space and time
required when using binary.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 13 of 170
Second, note that the maximum value of one digit in hexadecimal is equal to
the maximum value of four digits in binary. Thus, the value range of one digit
of hexadecimal is equivalent to the value range of four digits of binary.
Therefore, hexadecimal shortcut notation is a one-to-four reduction in the
volume of a memory dump.

Programmers may be required to reduce digits to a shortcut notation or to


expand a shortcut notation to its binary equivalent.

Table 5 - Relation of octal and hexadecimal to binary


DECIMAL BINARY OCTAL HEXADECIMAL
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10

1.1.4.1 Octal notation


Table 6 summarises the steps to convert from binary to octal, and to convert
from octal to binary.

Table 6 - Octal shortcut notation


BINARY TO OCTAL OCTAL TO BINARY
 Step 1 Divide the binary digits into Convert each octal digit to a
groups of three (starting three-digit binary number.
from the right). (Treat the octal digits as
decimals for this conversion).
 Step 2 Convert each group of three Run all of the resulting binary
binary digits into one octal groups into a single binary
digit using binary-to-decimal number.
conversion.

To convert binary to octal: Divide the binary digits into groups of three,
starting from the right. If the number of binary digits is not equal to a multiple
of three, zeros may be added to the left-hand side. Next, convert each group
of three binary digits into one octal digit. Use the binary-to-decimal conversion
method. Decimal digits 0 to 7 correspond with octal digits 0 to 7. Each group is

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 14 of 170
converted as if it were a separate entity. The rightmost bit of the group has a
column value of one; the second column has a value of two, and the third
column a value of four.

To convert octal to binary: Convert each octal digit to a three-digit binary


number. Again, since decimal and octal digits are equal from 0 to 7, the octal
digits may be treated as though they were decimal digits for this conversion.
Next, run together the resulting binary groups into a single binary number.
Figure 1.7 illustrates the conversion of binary 110011 to octal. The first step is
to divide the binary digits into one digit of octal. Binary 110 converts to octal
6, and 011 converts to octal 3. Binary 110011 is equal to octal 63.

1100112 = ?8

 Step 1: Divide the binary digits into groups of 3

110 011

 Step 2: Convert each group into 1 digit of octal

110 011
6 3

1100112 = 638

Figure 1.7 – Conversion from binary to octal

Figure 1.8 shows the expansion of octal to three binary digits. It may be
necessary to add zero to the left of the number to make groups of three binary
digits.

2468 = ?2

 Step 1: Convert each octal digit to 3 binary digits

2 4 6
010 100 110

 Step 2: Run the binary groups together

010 100 110

2468 = 0101001102

Figure 1.8 – Conversion from octal to binary

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 15 of 170
1.1.4.2 Hexadecimal notation
Table 7 lists the steps for the reduction of binary to hexadecimal and the
expansion of hexadecimal to binary.

Table 7 - Hexadecimal shortcut notation


BINARY TO HEXADECIMAL HEXADECIMAL TO BINARY
 Step 1: Divide binary digits into groups Convert the decimal equivalent
of four (starting from the right). of each hexadecimal digit into
four binary digits.
 Step 2: Convert each group of four Run all of the binary groups
binary digits to one hexadecimal into one binary number.
digit.

To reduce binary to hexadecimal: Divide the binary digits into groups of


four. Count off the binary groups, starting from the rightmost digit. Next,
convert each group of four binary digits to one hexadecimal digit. The binary
column values from right to left will be one, two, four, eight. It is convenient to
use the binary-to-decimal technique discussed earlier in this chapter, but
remember that resulting decimal values 10 to 15 should be written as
hexadecimal digits A to F.

To expand hexadecimal to binary: Convert the decimal equivalent of each


hexadecimal digit to four binary digits. Remember, hexadecimal digits 0 to 9
are equal to decimal digits 0 to 9, and hexadecimal digits A to F are equal to
decimal 10 to 15.

Figure 1.9 illustrates the reduction of binary 11010111 to its hexadecimal


equivalent. Step 1 divides the binary number into two groups of four digits.
Step 2 converts each group of four binary digits to one hexadecimal digit. In
this example, the binary reduces to hexadecimal A7.

110101112 = ?16

 Step 1: Divide the binary digits into groups of 4

1101 0111

 Step 2: Convert each group into 1 digit of hexadecimal

1101 0111
13 7
D 7

110101112 = D716

Figure 1.9 – Binary to hexadecimal

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 16 of 170
Figure 1.10 depicts the expansion of hexadecimal to its equivalent binary. The first
step is to convert the decimal equivalent of each hexadecimal digit to four binary
digits. The second step is to run the resulting groups of four binary digits into a
single string of binary.

2A916 = ?2

 Step 1: Convert each hexadecimal digit to 4 binary digits

2 A 9
2 10 9
0010 1010 1001

 Step 2: Run the binary groups together

0010 1010 1001

2A916 = 0010101010012

Figure 1.10 – Hexadecimal to binary

1.2 Addition and subtraction

1.2.1 Arithmetic
When a programmer is working with memory dumps to locate errors, simple
addition and subtraction of address values will be required. These addresses
will be either in octal or hexadecimal, depending on the computer's memory
organisation. In some cases, the programmer may also add or subtract binary
values to verify arithmetic results.

1.2.2 Addition
The steps required to add two numbers are the same in all number systems.
Therefore, the addition steps that are used for decimal numbers can also be
applied to adding binary, octal, and hexadecimal values. The easiest approach
to adding values of a number system other than decimal is to add the column
digits as if they were decimal. Because all binary and octal digit symbols are
also decimal symbols, adding them as decimal digits is easy. Hexadecimal
digits, however, use some symbols that are not included as decimal digits.
These additional symbols, A to F, should be converted to their equivalent
decimal values of 10 to 15 before the addition is attempted.

The general steps of addition are described in Figure 1.11. Addition always
begins by adding the rightmost column. If the column total is equal to or
greater than the value of the base, a 'carry-over' will occur. Whenever a 1 is
carried to the next column, the value being carried is equal to the value of the
base. As an example, if two decimal numbers were being added, and the first
column total was equal to 12, a 1 would be placed in the next column, which
would be a carry of 10 (the value of the base). Remember, a 1 in the 10s
column is equal to 10 in the 1s column. After carrying a 1 to the next column,

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 17 of 170
the remaining value is entered for the first column. These steps are repeated
for each column until the entire number has been added. Let us look at some
applications of these steps.

ADDITION
Step 1: Starting with the rightmost column, add the digits of the column
together.
Step 2: If the column total from Step 1 is equal to or greater than the base,
subtract the value of the base from the column total and carry a 1 to the next
column. If the column total is still equal to or greater than the base, repeat
Step 2.
Figure 1.11 - Steps in addition

1.2.2.1 Adding in decimal


The general addition steps can be demonstrated in decimal. Figure 1.12
illustrates the addition of 479 and 463. The first step is to add the 1s column of
9 and 3, for a total of 12. Because 12 is greater than a single digit in decimal,
a 1 must be carried to the next column. Because the value of the base is
always carried, a 2 is placed below the 1s column (12 minus 10). The next step
is to add the 10s column of 1, 7, and 6, for a total of 14. Again, a 1 must be
carried to the next column. The column total of 14 minus 10 (the base) leaves
a value of 4 in the 10s column. The last column of 1, 4, and 4, totals 9.
Because this value is indicated as a single digit, no carry occurs and the total is
equal to 942.

479
+ 463

 Step 1: Add the first column


1 (rightmost).
479  Step 2: If the column total from
+ 463 Step 1 is equal to or greater than
2
the base, subtract the value of the
base from the column total and
9+3=12=(10)+2
2 remains in this column carry a 1 to the next column.
carry over 1 group of 10 (a 1)

 Step 3: If there are additional


11 columns or carry occurred in Step
479 2, add the next column and repeat
+ 463 Step 2.
42
 Step 2: If the column total from
Step 3 is equal to or greater than
1+7+6=14=(10)+4
4 remains in this column the base, subtract the value of the
carry over 1 group of 10 (a 1) base from the column total and
carry a 1 to the next column.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 18 of 170
 Step 3: If there are additional
11 columns or carry occurred in Step
479 2, add the next column and repeat
+ 463 Step 2.
942  Step 2: If the column total from
Step 3 is equal to or greater than
1+4+4=9
9 remains in this column the base, subtract the value of the
no carry over base from the column total and
carry a 1 to the next column.

479
+ 463
942

Figure 1.12 – Adding in decimal

1.2.2.2 Adding in binary


The same addition steps used in adding decimal numbers can be applied to
binary. Figure 1.13 describes the steps necessary to add binary 10111 to
binary 01110. The first step is to add the 1s column of 1 and 0. The column
total is 1 and is a single binary digit, therefore, no carry occurs. The next step
is to add the next column of 1 and 1, which equals 2. Because a decimal value
of 2 cannot be indicated as a single digit in binary, a carryover will occur. To
carry, a 1 is placed above the column to the left. This carry is equal to the
value of the base (2 in binary). A 1 in the 2s column is equal to a 2 in the 1s
column.

Because a value of 2 out of a column total of 2 is being carried, the remaining


column value is 0. The third column values of 1, 1, and 1, total decimal is 3.
Again, a carry will result. A 1 in the fourth column carried 2 of the 3 leaving a
1 below the third column. The addition continues in the same manner for each
column.

10111
+ 01110

Step 1: Starting with the rightmost


10111 column, add the digits of the column
+ 01110 together.
1 Step 2: If the column total from Step
1 is equal to or greater than the base,
1+0=1
subtract the value of the base from the
1<2, so 1 remains in this
column column total and carry a 1 to the next
no carry over column.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 19 of 170
Step 3: If there are additional
1 columns or carry occurred in Step 2,
10111 add the next column and repeat Step
+ 01110 2.
01 Step 2: If the column total from Step
3 is equal to or greater than the base,
(1+1)=2
0 remains in this column subtract the value of the base from the
carry over 1 group of 2 (a 1) column total and carry a 1 to the next
column.

Step 3: If there are additional


11 columns or carry occurred in Step 2,
10111 add the next column and repeat Step
+ 01110 2.
101
Step 2: If the column total from Step
3 is equal to or greater than the base,
1+(1+1)=3
1 remains in this column subtract the value of the base from the
carry over 1 group of 2 (a 1) column total and carry a 1 to the next
column.
Step 3: If there are additional
11 columns or carry occurred in Step 2,
10111 add the next column and repeat Step
+ 01110 2.
0101
Step 2: If the column total from Step
3 is equal to or greater than the base,
(1+1)=2
0 remains in this column subtract the value of the base from the
carry over 1 group of 2 (a 1) column total and carry a 1 to the next
column.
Step 3: If there are additional
111 columns or carry occurred in Step 2,
10111 add the next column and repeat Step
+ 01110 2.
00101
Step 2: If the column total from Step
3 is equal to or greater than the base,
(1+1)=2
0 remains in this column subtract the value of the base from the
carry over 1 group of 2 (a 1) column total and carry a 1 to the next
column.
There are no more columns, so we
111 stop.
10111
+ 01110
100101

1=1
1<2, so 1 remains in this
column
no carry over

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 20 of 170
10111
+ 01110
100101

Figure 1.13 – Adding in binary

1.2.2.3 Adding in octal


Figure 1.14 shows the steps for adding octal 265 to octal 434. The first step is
to add the 1s column of 5 and 4, which totals decimal 9. Because the
maximum decimal value for a single digit in octal is 7, a carry must occur. A 1
is carried to the top of the next column, which carries a value equal to the
base (octal = 8). A 1 in the 8s column is equal to 8 in the 1s column. Since 8
of the column total of 9 have been carried, the difference of 1 is recorded
below the first column. The second column of 1, 6, and 3 totals decimal 10. A
carry of 1 to the third column carries the value of the base. Since 8 of the 10
in the second column have been carried, the difference of 2 is recorded below
the second column. The last column of 1, 2, and 4, totals decimal 7. Since
decimal 7 is equal to octal 7, no carry occurs and the 7 is recorded below the
third column.

265
+ 434

 Step 1: Add the first column


1 (rightmost).
265  Step 2: If the column total from
+ 434 Step 1 is equal to or greater than
1
the base, subtract the value of the
base from the column total and
5+4=9=(8)+1
1 remains in this column carry a 1 to the next column.
carry over 1 group of 8 (a 1)

 Step 3: If there are additional


11 columns or carry occurred in Step
265 2, add the next column and repeat
+ 434 Step 2.
21  Step 2: If the column total from
Step 3 is equal to or greater than
1+6+3=10=(8)+2
2 remains in this column the base, subtract the value of the
carry over 1 group of 8 (a 1) base from the column total and
carry a 1 to the next column.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 21 of 170
 There are no more columns, so we
11 stop.
265
+ 434
721

1+2+4=7
7<8, so 7 remains in this
column
no carry over

265
+ 434
721

Figure 1.14 – Adding in octal

1.2.2.4 Adding in hexadecimal


In Figure 1.15 hexadecimal 5A9 is added to hexadecimal A86. The first step of
adding 9 and 6 results in a total of decimal 15. Decimal 15 can be represented
as the single hexadecimal digit F and is recorded below the first column. The
second column adds A and 8. Hexadecimal A is equal to decimal 10. Therefore,
the column total is equal to decimal 18. Because 18 is greater than a single
hexadecimal digit, a 1 is carried to the third column. This carries 16 (the base)
of the total 18, and the remaining 2 is recorded below the second column. The
third column of 1, 5, and A (A = decimal 10) equals a total of 16. Again, the
column total exceeds the maximum size of one hexadecimal digit so carry
must occur. In carrying the value of the base (16), the entire column value of
16 is being carried, so a 0 is recorded for the third column. The last step is to
simply record the 1 from the last carry as the fourth column.

5A9
+ A86

 Step 1: Add the first column


5A9 (rightmost)
+ A86  Step 2: If the column total from
F Step 1 is equal to or greater than
the base, subtract the value of the
9+6=15=F
base from the column total and
15<16, so F remains in this
column carry a 1 to the next column.
no carry over

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 22 of 170
 Step 3: If there are additional
1 columns or carry occurred in Step
5A9 2, add the next column and repeat
+ A86 Step 2. Note: A = 10
2F  Step 2: If the column total from
Step 3 is equal to or greater than
A=10
10+8=18=(16)+2 the base, subtract the value of the
2 remains in this column base from the column total and
carry over 1 group of 16 (a 1) carry a 1 to the next column.

 Step 3: If there are additional


11 columns or carry occurred in Step
5A9 2, add the next column and repeat
+ A86 Step 2.
02F  Step 2: If the column total from
Step 3 is equal to or greater than
A=10
1+5+10=16=(16)+0 the base, subtract the value of the
remains in this column base from the column total and
carry over 1 group of 16 (a 1) carry a 1 to the next column.

 There are no more columns, so we


11 stop.
5A9
+ A86
102F

1=1
1<16, so 1 remains in this
column
no carry over

5A9
+ A86
102F

Figure 1.15 – Adding in hexadecimal

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 23 of 170
1.2.3 Subtraction
The principles of subtraction using decimal numbers can be applied to
subtraction of other bases as well. Figure 1.16 lists the two steps of
subtraction, which are repeated for each column of the numbers. The first step
is to determine if it is necessary to borrow. If the subtrahend (the lower digit)
is larger than the minuend (the top digit), it is necessary to borrow from the
column to the left. The value borrowed depends upon the base of the number.
The value borrowed is always the decimal equivalent of the base. Thus, in
binary, 2 is borrowed. Borrowing in octal borrows 8, and borrowing in
hexadecimal borrows 16. The second step is simply to subtract the lower value
from the top value.

SUBTRACTION
 Step 1: If the subtrahend digit of the column is larger than the minuend
digit, borrow from the column to the left. (Note: The value borrowed is
always equal in decimal to the value of the base.)
 Step 2: Subtract the lower value from the top value.
Figure 1.16 - Steps in subtraction

1.2.3.1 Subtraction in decimal


The general subtraction steps can be demonstrated with decimal values. Figure
1.17 shows the steps for subtracting decimal 183 from decimal 346. The first
operation is to determine if borrowing is necessary. 3 is less than 6, so no
borrowing is required. 3 is subtracted from 6, and the remainder of 3 is
recorded. The second column is subtracting 8 from 4, therefore, borrowing is
required. A 1 is borrowed from the column to the left (leaving 2). Since the
base is 10, 10 is the value being borrowed. The 4 in the second column and
the 10 borrowed make 14. Taking 8 from 14 leaves 6. The third operation is to
subtract 1 from the remaining 2 in the third column. These general steps can
be applied to any number system.

346
- 183
1st operation 2nd operation
(Steps 1 and 2)

3rd operation

Figure 1.17 – Subtracting in decimal

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 24 of 170
1.2.3.2 Subtracting in binary
Figure 1.18 illustrates the first steps of subtracting binary 01110 from binary
10101. The first column does not require borrowing, and the 0 is subtracted
from 1, leaving 1. In the second column 1 is subtracted from 0, so borrowing
must occur. A 1 is borrowed from the column to the left (leaving 0). The 1
borrowed from the third column becomes 2 in the second column. In the third
operation, the third column is also subtracting 1 from 0, and borrowing is
again required. The fourth column contains a 0 and thus has nothing to lend.
Therefore, the borrowing must be from the fifth column. Borrowing 1 from the
fifth column gives two in the fourth column, leaving 0 in the fifth. Now the
fourth column has something to lend for the fourth operation. When 1 of the 2
in the fourth column is borrowed, it becomes 2 in the third column, leaving 1 in
the fourth. The subtraction of 1 from 2 gives a difference of 1. In the fifth
operation, 1 is subtracted from 1 in the fourth column, giving 0, and
subtraction of the fifth column is 0 from 0, leaving 0 (the sixth operation).

NOTE Remember that binary values have a base of 2 and that is why 2 is
borrowed instead of just one.

10101
- 01110
1st operation (Steps 1 and 2 from 2nd operation
Table 9)

3rd operation 4th operation

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 25 of 170
5th operation 6th operation

Figure 1.18 – Subtracting in binary

1.2.3.3 Subtraction in octal


If borrowing is required in octal, the decimal equivalent of 8 is borrowed.
Figure 1.19 shows the subtraction of octal 275 from octal 734.

In the first column, 5 is subtracted from 4, so borrowing is necessary.


Remember, 1 in the 8s column is equal to 8 in the 1s column. When 1 is
borrowed from the second column, 8 is added to the first column, giving a total
of 12 (in decimal). Taking 5 from 12 results in a 7 for the first column. In the
second column, 7 is subtracted from 2, and borrowing is again required.
Borrowing 1 from the third column adds 8 to the second column, for a total of
10. Subtracting 7 from 10 results in a difference of 3. In the third column 2 is
taken from 6, leaving 4.
7 3 4
-2 7 5
1st operation (Steps 1 and 2 from 2nd operation (Steps 1 and 2 from
Table 1.7) Table 1.7)

3rd operation (Steps 1 and 2 from


Table 1.7)

Figure 1.19 – Subtracting in octal

1.2.3.4 Subtracting in hexadecimal


Subtracting in 'foreign' number systems is most easily done using decimal
equivalent values. When subtracting in hexadecimal, it is necessary to first
convert the hexadecimal digits of A through F to their decimal equivalents
before subtracting. Figure 1.20 illustrates the subtraction of hexadecimal 48F
from hexadecimal A7B. The first column is the subtraction of F from B (or, in
decimal, subtraction of 15 from 11). Borrowing is required. Borrowing 1 from
the second column adds 16 to the first column. In the first column, 15 is now
subtracted from 27, resulting in 12. Because this subtraction result is in

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 26 of 170
decimal, the 12 must be converted to a hexadecimal C. In the second column,
8 is subtracted from 6, and again borrowing is necessary. Borrowing 1 from
the third column adds 16 to the second column, for a total of 22. Taking 8
from 22 is equal to decimal 14, or hexadecimal E. In the last column, 4 is
subtracted from 9, leaving 5.

A7B
-48F
1st operation (Steps 1 and 2 from 2nd operation
Table 1.7).

3rd operation

Figure 1.20 – Subtracting in hexadecimal

1.3 Complements and overflows

1.3.1.1 Arithmetic on computer hardware


Computer manufacturers design and build computers to solve real-world
problems. Consequently, computers need the ability to analyse both positive
and negative mathematical values correctly.

Computer manufacturers want to solve real-world problems in the simplest and


most cost-effective way, and therefore have designed hardware that uses the
most cost-effective techniques for providing computer arithmetic.

An important cost consideration is the size of the numbers that the computer
will handle. The computer manufacturer has to design the computer to handle
numbers of a specific maximum size. For example, some computers handle
numbers of no more than eight digits (bits), and are much cheaper to produce
than computers that can handle numbers of sixty-four bits and larger.

1.3.1.2 Representing negative numbers in hardware


(A computer that works with only six digits will be considered for this
discussion.)

Most computer manufacturers distinguish between positive and negative


numbers by designating the leftmost bit as an indicator of whether a number is
positive or negative.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 27 of 170
If this sign bit is a zero, the number is positive and the remaining five bits
represent the value of the number. If the leftmost sign bit is a one, the
number is considered negative and the remaining five bits represent the value
of the negative number.

Example: 001011 (binary) = +11 (decimal)

The first leftmost bit is zero, which indicates that the number is positive. If the
remaining five bits are converted to decimal, the following is concluded:

(1 x 8) + (1 x 2) + (1 x 1) = 8 + 2 + 1 = 11 (decimal).

Conversely: 101011 (binary) = -11 (decimal)

This is a negative number because the leftmost bit is a one. The value of this
negative number is represented by the last five bits. Therefore, this is -11
decimal. Table 8 shows the possible positive and negative numbers using a
sign bit and five value bits.

Table 8 - Positive and negative numbers


POSITIVE NEGATIVE
000 000 +0 100 000 -0
000 001 +1 100 001 -1
000 010 +2 100 010 -2
: : : :
: : : :
011 111 +31 111 111 -31

Since the leftmost bit was reserved for the sign, the maximum quantity that
can be represented with five bits is +31, and the minimum is -31. The earliest
computers used this method of sign bits and quantities. Computer hardware
was built to recognise positive and negative numbers and to add or subtract
them accordingly. However, this method meant installing complex hardware
circuits. As a result, this method was soon abandoned in favour of what is
called complement arithmetic.

1.3.2 Complement arithmetic


The sign bit is still used in complement arithmetic. The leftmost bit is either 0
for a positive number, or 1 for a negative number. The negative numbers are
represented as the mathematical complement of the positive numbers. There
are two ways to complement binary numbers:

 Change all the 0s to 1s and all the 1s to 0s. This is called One's
Complement.
 Take the one's complement and then add one to the result. This is called
Two's Complement.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 28 of 170
1.3.2.1 One's complement
The following example shows how a one's complement is obtained by changing
every one in the number to a zero and every zero in the number to a one.

NOTE This method will always change the sign of the number.

The sign bit is the first leftmost bit. If the number is positive to start with (sign
bit = 0), the one's complement will make it negative (sign bit = 1).

Add the six-bit binary numbers 001010 (10 decimal) and 000011 (3 decimal).

The answer is 001 101 (binary) which equals 13 (decimal).

Computers can be built economically to handle such additions and can even be
built to subtract, but it is more economical to perform addition only. Here is
where complements play an important role.

Consider the following problem of (10 - 3) in binary.

Subtraction Complement addition


001 010
- 000 011
000 111

In the above example, 10 minus 3 equals 7 (000111 in binary). Examine the


complement version. 1000110 (binary) does not equal 7 (decimal) – it equals
-6 (decimal), which is not the correct answer for 10 – 3. To get the correct
answer (000111) by using complement arithmetic, another step must be
taken. Notice that the result of the complement addition is a seven-bit number.
Because computers allow only six-bit answers (as previously mentioned, it was
limited for this discussion), the extra leftmost bit causes what is termed an
overflow condition. The answer contains more bits than the computer allows.
When an overflow occurs, drop the extra bit from the left and add it to the
sum:

The correct answer wanted, namely 7 (000 111) is now obtained.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 29 of 170
This is the way one's complement arithmetic works. The extra bit, or overflow
bit, is added to the sum to give us the correct answer. Table 1.9 summarises
what is to be done when adding or subtracting.

Table 9 - One's complement


In one's complement arithmetic, remember the following:
Subtracting: Take the one's
complement of the number we are
Adding: Add the numbers directly
subtracting and add it to the other
(for example normally).
number. Then add back the overflow
bit to get the correct answer.

NOTE It is easier to build computers that use complement arithmetic than


it is to build them to add and subtract.

1.3.2.2 Two's complement


While one's complement simplified computer hardware, computer
manufacturers soon realised that there was a way to simplify matters even
further.

They found it was better to handle arithmetic with two's complement rather
than one's complement. The two's complement of a binary number is obtained
by following two steps:

Step 1 Take the one's complement by changing all 0s to 1s and all 1s to 0s.
Step 2 Add 1 to the one's complement.

Example: The two's complement of 3 (decimal) with six bits is as follows:

Now compare one's complement and two's complement using the problem (10
- 3) = 7 (decimal).

Both additions resulted in an overflow bit. In the case of the one's


complement, the bit had to be added back in. In the case of the two's
complement, the overflow bit is discarded and the answer is the last three bits.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 30 of 170
With two's complement arithmetic, there is a two-step procedure, but only a
one-step addition procedure. Two's complement arithmetic is more efficient
than one's complement arithmetic, and is therefore used in modern computers
instead of one's complement arithmetic. Table 1.10 contrasts one's and two's
complements.

Table 10 - One's and two's complements


Binary One's Two's
complement complement
000 000 111 111 1000 000
000 001 111 110 111 111
011 110 100 001 100 010
011 111 100 000 100 001

1.3.3 Overflow
Overflow occurs when the number of bits resulting from an arithmetic
operation exceeds the maximum number of bits that the computer can handle.
This occurred earlier with complement arithmetic. The example we examined
caused no problem. However, some overflow can cause problems.

Examine the following example:

Binary Decimal

The number 27 has been added to 16 to give 43, but look at the binary. Two
positive numbers have been added and obtained a negative binary number. It
is negative because the leftmost sign bit is 1. This is problematic because
adding two positive numbers cannot have a negative result. When two positive
numbers are added to give a negative number in binary, the error that occurs
is called a size error. In other words, a size error occurs when the result of an
arithmetic operation exceeds what the computer allows. This can be thought of
as a 'value overflow' - the limit of +31 has been exceeded by 12! The leftmost
(sixth) bit is reserved for the sign (+ or -) and the remaining five bits have a
maximum value of 31 (11111 in binary).

How an overflow error is handled depends on what caused the overflow.


Overflow occurs in all computers. In some cases, the overflow is not a
problem, and in other cases, it indicates that some type of error has occurred.
Computers are built to let the programmer know that an overflow has
occurred. It is then up to the programmer to decide what needs to be done.

1.3.4 Complements and overflows - summary


Computer arithmetic is commonly done using complements. In today's
computers, two's complement arithmetic is more efficient and economical to
use than any other method.
Because computers have a fixed number of bits, it is possible for overflows to
occur. Overflow may or may not cause a problem depending on what caused it.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 31 of 170
Understanding the limitations and capabilities of a computer can help you to
become a more efficient and effective computer programmer.

1.4 Key terms

 Binary
 Octal
 Hexadecimal
 One's complement
 Two's complement
 Overflow

1.5 Exercises

1. Convert the following decimal numbers to octal using the successive division
method:
a. 2
b. 7
c. 13
d. 19

2. Convert the following octal numbers to decimal:


a. 67
b. 245
c. 624
d. 1637

3. Convert the following decimal numbers to hexadecimal using the successive


division method:
a. 33
b. 11
c. 15
d. 67

4. Convert the following hexadecimal numbers to decimal:


a. DD
b. 7E
c. F44
d. E10

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 32 of 170
5. Obtain the hexadecimal equivalent of the following octal numbers by first
converting to binary:
a. 63
b. 72
c. 147
d. 361

6. Using the octal addition table, add the following numbers:


a. 62 + 47
b. 457 + 347
c. 643 + 745
d. 7254 + 4665

7. Using the hexadecimal addition table, add the following hexadecimal


numbers:
a. 56 + A9
b. 789 + E08
c. 58A6 + FD47
d. 4167 + AC09

8. Solve the following subtraction problems in binary:


a. 101110 – 11011
b. 1001110 – 11010
c. 1101101 – 1011100
d. 111111 – 11011

9. Subtract the following octal numbers:


a. 145 – 77
b. 144 – 57
c. 324 – 262
d. 6435 – 5365

10. Subtract the following hexadecimal numbers:


a. 1F – B
b. 61C – 95
c. 7A4 – 5E9
d. 1073 – 3A7

11. Subtract the following binary numbers: 1111 – 0011

12. Add the following octal numbers: 734 + 172 + 63 + 547

13. Subtract the following binary numbers: 10011001 – 111111

14. Add the following octal numbers: 743 + 571 + 777 + 453 + 737

15. Octal 42 plus octal 31 equals octal________

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 33 of 170
16. Hexadecimal 1B plus hexadecimal 11 equals hexadecimal_______

17. Binary 100110 – 100011 equals__________

18. Octal 255 – 156 is ____________________

19. Convert 10100 (base 2) to base 8

20. Convert 1111 (base 5) to decimal

1.6 Revision questions

1. To convert any other number system to decimal, first:


A. multiply the LSD (Least Significant Digit) of the number by the base.
B. multiply the MSD (Most Significant Digit) of the number by the base.
C. divide the number by the base.
D. None of the above.

2. The largest single digit in our common decimal number system is:
A. nine
B. same as the base
C. both A and B are correct
D. one more than the base

3. In binary-to-decimal conversion, each bit is:


A. twice the value of the bit to its left.
B. half the value of the bit to its left.
C. same as the value of the bit to its left.
D. quarter of the value of the bit to its left.

4. In converting from decimal to any other number system, first:


A. convert to binary and then divide.
B. multiply by the base of the desired number system.
C. divide number by base of system being converted to.
D. divide the number by 10.

5. The decimal equivalent of octal 31 is: _____.


A. 25
B. 31
C. 89
D. 75

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 34 of 170
6. The hexadecimal equivalent of decimal 864 is: _____.
A. 4E
B. 360
C. 55A
D. B84

7. The octal equivalent of decimal 278 is: _______.


A. 362
B. 426
C. 556
D. 238

8. The decimal equivalent of binary 10101 is:


A. 19
B. 21
C. 30
D. 42

9. Converting 19 (base 16), first to binary and then to octal, the answer is:
A. bin = 00110, oct = 13
B. bin = 01010, oct = 11
C. bin = 11001, oct = 31
D. bin = 10101, oct = 33

10. Converting 309 (base 16), first to binary and then to octal, the answer is:
A. bin = 0011110110, oct = 1141
B. bin = 0011001100, oct = 1114
C. bin = 0011110110, oct = 1411
D. bin = 1100001001, oct = 1411

11. Converting C143 (base 16), first to binary and then to octal, the answer is:
A. bin = 1100000101000011, oct = 305041
B. bin = 1100000101000011, oct = 140503
C. bin = 0011111010111100, oct = 305041
D. bin = 0011111010111100, oct = 140503

12. Converting 24F8 (base 16), first to binary and then to octal the answer is:
A. bin = 10010011111000, oct = 22370
B. bin = 01101100000111, oct = 22370
C. bin = 01101100000111, oct = 07322
D. bin = 10010011111000, oct = 07322

13. Converting 87 (base 10), first to binary and then to hexadecimal, the
answer is: ____________.
A. bin = 0101000, hex = 57
B. bin = 0101000, hex = 75
C. bin = 1010111, hex = 75
D. bin = 1010111, hex = 57

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 35 of 170
14. Converting 163 (base 10), first to binary and then to hexadecimal, the
answer is:
A. bin = 01011100, hex = 3A
B. bin = 01011100, hex = A3
C. bin = 10100011, hex = A3
D. bin = 10100011, hex = 3A

15. Converting 4910 (base 10), first to binary and then to octal, the answer is:
A. bin = 1001100101110, oct = 65411
B. bin = 1001100101110, oct = 11456
C. bin = 0111010011001, oct = 11456
D. bin = 0111010011001, oct = 65411

16. Converting 3598 (base 10), first to binary and then to octal, the answer is:
A. bin = 011100000111, oct 7016
B. bin = 111000001110, oct 7016
C. bin = 111000001110, oct 6107
D. bin = 000111110001, oct 7016

17. Converting 7985 (base 10), first to binary and then to octal, the answer is
A. bin = 1111100110001, oct = 17461
B. bin = 1111100110001, oct = 16471
C. bin = 0000011001110, oct = 17461
D. bin = 0000011001110, oct = 16471

18. Convert 819 base 10 to binary, octal and hexadecimal, the answer is:
A. 1100110011, 1463, 120C
B. 1100110011, 1507, 333
C. 1001000001110, 1463, 120E
D. 1100110011, 1463, 333

19. Convert 10000011101 to its octal equivalent, the answer is:


A. 2036
B. 2136
C. 2305
D. 2035

20. Convert 1110011 (binary) to decimal, the answer is:


A. 115
B. 234
C. 453
D. 75

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 36 of 170
Unit 2 - Logic Gates and Truth Tables

At the end of this unit you will be able to:

 Understand the basics of binary logic.


 Identify the main logic operators.
 Recognise and draw logic symbols.

2.1 Introduction to logic concepts

This section on logic concepts lays the foundations for program design and
programming.

Here logic systems which shaped the evolution of the modern computer are
explored. Many discoveries will be made throughout this module. One of these
is that all computers are designed around logic circuits known as logic gates
or Boolean gates. Another discovery will be how technology used to
implement those gates has gone through many rapid changes since the first
computers were developed.

The very first electronic gates were created using relays, but these gates were
slow and bulky. Relays were replaced by vacuum tubes, which were much
faster, but they were also bulky as well as being unreliable and high in power
consumption. Vacuum tubes were replaced by transistors, which were invented
in 1947. Transistors were used to make gates in computers because they were
compact, reliable, and used relatively little power. Integrated circuits were
invented in the early 1960s, which meant transistors could be made together
on silicon 'chips'. First arrived Small Scale Integration (SSI) with integrated
circuits typically consisting of 20 transistors etched into a silicon chip. Next
arrived Medium Scale Integration (MSI) with chips containing components
made up of multiple gates. Large Scale Integration (LSI) made it possible to fit
all the components of a simple microprocessor onto a single chip, containing
over 4 000 transistors. Finally, Very Large Scale Integration has seen the
steady increase in the number of transistors since the early 1970s. The first
Pentium processor was released in 1993 with 3.2 million transistors.

2.2 Logic symbols and logic gates


2.2.1 Binary logic
 Binary logic forms the basis of all computer operations.
 This logic has evolved by adapting the principles of reasoning to the nature
of the electronic components that make up computers.
 Computers represent data by using a binary system that is well suited to
the fact that electronic components can be in only one of two possible
states at any given time – never both simultaneously. Similarly, computers

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 37 of 170
use a binary system of logic in which variables can have only one of two
possible values, zero or one.
 Binary logic uses the three basic logic operations, which can be illustrated
using Venn diagrams as shown in Figure 2.1.

Figure 2.1 – Venn diagrams showing three basic logic operators

 In computers, these logic operations are incorporated into electronic circuits


in the form of 'logic gates', which act on binary variables.
 These logic gates are used to apply to incoming binary signals, the logic
principle on which the gate is based.
 Logic gates form the basic components of digital computer circuits, and
these will be looked at in more detail later on.
 The way a logic gate works is best illustrated by the truth table derived
from the logic principle the gate represents.
 A truth table is used to find the result of logic operations on binary
variables.
 If truth tables are not familiar, pay particular attention to the following
example.

If given the statement: 'If it is NOT raining, then I will go out', it can be said
that 'It is raining' is either TRUE or FALSE, and consequently, 'I will go out' will
be either TRUE or FALSE. This logic relationship can be expressed in a table,
called a truth table. Consider Table 11.

Table 11 - Simple truth table


RAINING GO OUT
FALSE TRUE
TRUE FALSE

 The bistable nature of computer components is at the heart of binary logic,


which effectively models a computer's means of operating.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 38 of 170
 Remember, a bistable device can be in one of two possible states – never
in both at the same time. For instance, a lamp is either on or off. Electrical
current either flows or there is no current. A statement is either true or
false.
 In binary, a value is either one or zero, so in binary logic we assign a value
of 1 to one state and a value of zero to the other.
 A lamp that is on represents a '1', while a lamp that is off represents a '0'.
Similarly, a statement that is true represents a '1' and a statement that is
false represents a '0', or a circuit that is closed represents a '1' and an open
circuit represents a '0'.

By convention, ON = TRUE = YES = 1 and OFF = FALSE = NO = 0.

Below is a more detailed look at the three basic binary operations that are
used to indicate relationships between binary variables.

2.2.2 Binary operators


2.2.2.1 The AND operator
 The AND operator is indicated by a dot (.), or by the absence of an
operator. For example, we write A. B = L or AB = L.
 Both mean: 'A AND B is equal to L'.
 We can simulate this operation using a circuit with two switches in series as
shown in Figure 2.2.

Figure 2.2 – Circuit simulating the AND operator

The truth table for the AND circuit is shown in Table 12.

Table 12 - Truth table for the AND circuit


A B Light
open open off
open closed off
closed open off
closed closed on

NOTE A truth table is a table containing all possible combinations of the


input variables, as well as the result of one or more logical operations
on the input variables.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 39 of 170
 The truth table for the AND circuit can be expressed in binary terms by
allocating a value of 1 to A and B if they are both closed, and a value of 0 if
they are both open.
 Let L = 1 if the light is on and let L = 0 if the light is off.
 The truth table for the AND operator now looks like the one shown in
Table 2.3.

Table 13 - Truth table for the AND operator


A B L=A.B
0 0 0
0 1 0
1 0 0
1 1 1

2.2.2.2 The OR operator


 This operator is indicated by a plus sign (+).
 Write A + B = L.
 This means: 'A OR B is equal to L'.
 Again the operation using a circuit with two switches is simulated, but this
time they are linked in parallel as shown in Figure 2.3.

Figure 2.3 – A circuit simulating the OR operator

The truth table for the OR circuit is shown in Table 14.

Table 14 - Truth table for the OR circuit


A B Light
open open off
open closed on
closed open on
closed closed on

 This can be expressed in binary terms by replacing closed with 1, open with
0, off with 0, and on with 1 to obtain the truth table for the OR operator
shown in Table 2.5.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 40 of 170
Table 15 - Truth table for the OR operator
A B L=A+B
0 0 0
0 1 1
1 0 1
1 1 1

2.2.2.3 The NOT operator


 This operator is indicated by a prime or a small horizontal line.
 Write: A' = C or A̅=C
 Both mean: 'A complement' or 'A NOT is equal to C'.
 This means that A is not equal to C or that C is what A is not!
In other words, if A = 1, then C = 0 and if A = 0, then C = 1.
 The truth table for the NOT operator is shown in Table 16.

Table 16 - Truth table for the NOT operator


A A'
0 1
1 0

 As seen before, simple circuits can be described using binary logic.


 The two circuits in the previous section can be expressed as follows in
terms of binary logic:

L = A . B (for serial switches) L = A + B (for parallel switches).

In the following section, binary logic is explored to show how to design and
analyse electronic circuits.

2.2.3 Logic gates: AND, OR, NOT

NOTE An electronic switching circuit that performs a function similar to the


logical operations AND, OR, NOT is called a logic gate or logic circuit.

 Logic gates can be combined in various ways to create some of the


important components of computers, such as the memory registers.
 See Figure 2.4.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 41 of 170
LOGIC GATES

 Switching circuits that perform certain simple operations on binary


signals.
 Have one or two inputs.
 Have one output.
 Inputs and output is one bit in size with a value of either 0 or 1.

0 = FALSE
1 = TRUE

 Basic building blocks of computers and all other digital devices.


 Can be combined to perform useful and more complex functions.

Input
Logic Output
gate

Figure 2.4 – Block diagram representation of a logic circuit

NOTE The voltage ranges for 0 or 1 are separated by a neutral range so that
no confusion can arise as to whether a certain voltage represents a 0
or 1. In Boolean algebra, the symbol which represents a gate is called
a logic symbol.

2.2.3.1 The AND gate


 The logic circuit which performs the same function as the AND operator
is called the AND gate and is symbolically represented in Figure 2.5.

A
(Inputs) C (Output)
B

Figure 2.5 – Symbolic representation of an AND gate

The truth table (Table 2.7) is the same as that of the AND operator.
Figure 2.6 shows how an AND gate works.

Table 17 - AND
A B C
0 0 0
0 1 0
1 0 0
1 1 1

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 42 of 170
AND

AND

AND

AND

True, on, or 1

False, off, or 0

Figure 2.6 – How an AND gate works

2.2.3.2 The OR gate


 The logic circuit that performs the same function as the OR operator is
called the OR gate and is represented symbolically in Figure 2.7.

A
(Inputs) C (Output)
B

Figure 2.7 – Symbolic representation of an OR gate

 The truth table (Table 18) is the same as that of the OR operator.
 Figure 2.8 shows how an OR gate works.

Table 18 - OR
A B C
0 0 0
0 1 1
1 0 1
1 1 1

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 43 of 170
OR

OR

OR

OR

True, on, or 1
=

False, off, or 0

Figure 2.8 – How an OR gate works

2.2.3.3 The NOT gate


 Figure 2.9 is a symbolic representation of the NOT gate (also called an
inverter).

(Input) A A’ (Output)

Figure 2.9 – Symbolic representation of a NOT gate

 With the aid of a truth table (Table 19), the behaviour of this gate can be
described as follows (NOTE it is the same as that of the NOT operator):

Table 19 - NOT
A A'
0 1
1 0

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 44 of 170
2.2.4 Additional logic gates
 The additional gates that will be dealt with in this module are the NAND,
NOR, XOR, and XNOR gates.
 A table of all gates with definitions and truth tables is given at the end of
this section.

2.2.4.1 The NAND gate


AND and NOT = NAND
 The NAND gate is equivalent to an AND gate followed by an inverter as
shown in Figure 2.10.

A C = A.B D = C’ = (A.B)’

Figure 2.10 – Equivalent representation of a NAND gate

 The NAND gate is symbolically represented in Figure 2.11.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 45 of 170
State
indicator

A
D
B

Figure 2.11 – Symbolic representation of a NAND gate

NOTE A state indicator is a symbol which is located at the input or output


of a logic symbol to indicate that an inversion of signal has taken
place.

The truth table for a NAND gate can be derived as shown in Table 20.

Table 20- NAND


A B C = A.B D = C' A B D
0 0 0 1 0 1 1
0 1 0 1 0 1 1
1 0 0 1 1 0 1
1 1 1 0 1 1 0

NOTE The output of a NAND gate is 0 only in the case when all inputs are
equal to 1. For all other combinations of input values the output will
be equal to 1.

2.2.4.2 The NOR gate


OR and NOT = NOR
 The NOR gate is the equivalent of an OR gate followed by an inverter as
illustrated in Figure 2.12.
 Figure 2.13 is a symbolic representation of a NOR gate.

A C=A+B D=C=A+B

Figure 2.12 – Equivalent representation of a NOR gate

A
D
B

State indicator

Figure 2.13 – Symbolic representation of a NOR gate

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 46 of 170
The truth table for a NOR gate can be derived as shown in Table 21.

Table 21 - NOR
A B C= D = C' A B D
A+B
0 0 0 1 0 0 1
0 1 1 0 0 1 0
1 0 1 0 1 0 0
1 1 1 0 1 1 0

2.2.4.3 The XOR gate (Exclusive OR)


The XOR gate is used for the expression A.B' + A'.B
Or: A⨁B

 The truth table for the XOR gate is derived as shown in Table 22.

Table 22 - XOR
A B A' B' AB' A'B AB' +
A'B
0 0 1 1 0 0 0
0 1 1 0 0 1 1
1 0 0 1 1 0 1
1 1 0 0 0 0 0

 Figure 2.14 shows the symbolic representation of an XOR gate.

A
F
B

Figure 2.14 – Symbolic representation of an XOR gate

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 47 of 170
 The truth table for an XOR gate can be derived as shown in Table 2.13.

Table 23 - Truth table for the XOR gate


A B F
0 0 0
0 1 1
1 0 1
1 1 0

NOTE XOR: Output will be TRUE [1], if only one of the inputs is TRUE [1],
but not both.

2.2.4.4 The XNOR gate (Exclusive NOR)


The XNOR gate is used for the expression AB + A'B'

 Figure 2.15 shows the symbolic representation of an XNOR gate.

A
F
B

Figure 2.15 – Symbolic representation of an XNOR gate

 Table 24 shows all the logic gates.

Table 24 - Logic gates


Gate Circuit Symbol Function Logic Truth
Symbol table
AND x y F
F = x.y 0 0 0
. or
The result is true or 0 1 0
nothing
only if both F = xy 1 0 0
variables are true. 1 1 1
OR x y F
0 0 0
The result is true if
either variable is
F=x+y + 0 1
1 0
1
1
true. 11 1
NOT
F = x' x F
The Inverter x F or ' or 0 1
changes F=x 1 0
true to false and
false to true.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 48 of 170
Buffer
F=x x F
No
Makes no change 0 0
Symbol
to input. 1 1

NAND
F = (xy)' x y F
The result is false or 0 0 1
only if both F = xy 0 1 1
variables are true. 1 0 1
1 1 0

NOR x y F
x F = (x + y)' 0 0 1
The result is false F or 0 1 0
y
if either variable is F=x+y 1 0 0
true. 1 1 0
XOR x y F
F = xy' + x'y 0 0 0
The result of the or 0 1 1
Exclusive OR is F=x y 1 0 1
true if only one of 1 1 0
the variables is
true.

XNOR x y F
F = xy + x'y' 0 0 1
The result of the Or 0 1 0
Exclusive NOR is 1 0 0
false if only one of F= x y 1 1 1
the variables is
true.

2.2.5 Truth table examples


Below are two examples, of which one is a bit easier than the other. The
purpose of these examples is to show how different variables can be used to
carry out the same principles. Although the variables in one expression differ
from the other expression, the calculations are still the same!

For example: A + B = B + A
 Draw your truth table.
LHS RHS  Fill in all possible values for all
A B A+B B+A variables.
1 1 1 1  Fill in results for the left-hand-
side (LHS) and the right-hand-
1 0 1 1
side (RHS) of the equation.
0 1 1 1
 If your LHS = RHS then the
0 0 0 0
equation is true.
For all the values of A and B, LHS = RHS, therefore A + B = B + A. Now using
different variables, the same calculation will be done: X + Y = Y + X.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 49 of 170
LHS RHS
X Y X+Y Y+X
1 1 1 1
1 0 1 1
0 1 1 1
0 0 0 0

For all the values of X and Y, LHS = RHS, therefore X + Y = Y + X.


The next example is a bit more difficult: x.x = x

LHS RHS
x x x.x x
1 1 1 1
0 0 0 0

For all the values of x, LHS = RHS, therefore x.x = x.

2.3 Key terms

 The AND, OR, and NOT operator.


 The AND, OR, NOT, XOR, and XNOR gates.
 Truth table

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 50 of 170
2.4 Exercises

21. Given that the values of the following binary variables are as follows:
A = 1, B = 0, C = 1, and D = 0.
Calculate:
a. A. B
b. A + B
c. A + C
d. A'
e. D'
f. A. C
g. B + D

22. Draw up the truth table for the exclusive NOR gate. What does this show –
i.e. what can you deduce from this?

23. Prove the following using truth tables:


a. x + 0 = x
b. (x')' = x
c. x.x' = 0
d. (x + y) + z = x + (y + z)
e. x. (y + z) = x.y + x.z
f. A + A'B' = A + B'
g. AB + A'C + BC = AB + A'C
h. (A + B)' = A'B'
i. (AB)' = A' + B'

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 51 of 170
2.5 Revision questions

1. A fire alarm rings when there is smoke and when the temperature exceeds
50 degrees Celsius. The logical statement to control the alarm would be:
A. ((SMOKE) + (TEMP > 50))
B. (TEMP > 50)
C. (SMOKE)
D. ((SMOKE) . (TEMP > 50))

2. Which one of the following is true?


A. True AND (True AND False)
B. True AND (True OR False)
C. True AND (False AND False)
D. True AND (False OR False)

3. Which is the odd one out?


A. true
B. yes
C. 0
D. on

4. Which of the following is true?


A. 1 AND 0
B. 1 AND 1 AND 0
C. 1 OR 0
D. 0 OR 0

5. Which of the following is incorrect?


A. 1 AND (1 OR 0) = 1
B. 0 OR 1 AND (1 OR 0) = 1
C. 1 AND 0 OR (1 AND 1) = 0
D. 1 OR 0 AND 1 = 1

6. Which of the following in the list below is false? (A = 1, B = 1, C = 1, D = 1,


E = 0)
A. (A AND B) AND (D OR C)
B. (E OR A) AND B
C. A AND D
D. (A AND C) AND E

7. Which of the following is false?


A. 1 AND 1 OR 1
B. 1 AND 1 AND 0
C. 0 OR 1 OR 0
D. 1 OR 1 AND 1

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 52 of 170
8. Which of the following is correct?
A. 1 AND 1 AND 0 = 0
B. 1 OR 0 AND 1 = 0
C. 1 OR 1 OR 0 = 0
D. 1 AND 0 AND 1 = 1

9. Which of the following is false?


A. 1 AND 1
B. 0 OR 1 AND 1
C. 1 AND 0 AND 1
D. 1 AND 1 AND 1

10. Which is the odd one out?


A. off
B. 0
C. no
D. on

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 53 of 170
Unit 3 - Converting Boolean Algebra

At the end of this unit you will be able to:

 Identify and draw the symbols of Boolean algebra.


 Understand and draw logic diagrams.
 Draw logic diagrams from Boolean equations and vice versa.

3.1 Introduction to Boolean algebra

For centuries mathematicians were unsuccessful in their attempts to solve logic


problems using conventional algebra. Only in 1854 did British philosopher
George Boole develop a mathematical system of logic to express truth
functions as symbols, and then manipulate these symbols to arrive at a
conclusion. In other words, Boole developed algebra of logic, but his work
was not applied practically for another 84 years. In 1938, engineer Claude
Shannon of the Bell Telephone Company used Boole's algebraic system to
solve relay logic problems. Since that time, this treatment of electrical circuits
has enormously simplified work in the telephone and computer fields. Just as
rhetorical logic problems are binary decisions, either true or false, relay
problems are also binary, either energised or not energised. Shannon's
application of Boole's theory to binary relay logic problems led directly to the
development of what is known today as Boolean algebra, which can be used
to solve any electronic or logic circuit involving only two possible states.

3.2 Characteristics

The characteristics of Boolean algebra may be summarised as follows:

 Describes logical processes.


 Any device having two conditions may be represented by a Boolean algebra
equation.
 Sometimes referred to as the mathematics of logic or the algebra of logic,
Boolean algebra lends itself well to electrical applications such as the
switching circuits used in computers.
 Boolean algebra permits detailed computer schematics to be simplified, and
therefore is a great asset in computer design and troubleshooting.
 It allows complex logic circuits, made up of binary conditions, to be
simplified and reduced.
 Boolean algebra provides a way of doing calculations with expressions,
which is more convenient than having to use schematic or logic diagrams.
 It also provides an economical and straightforward way of describing the
circuitry used in digital computers.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 54 of 170
 Variables are represented by letters and logic conditions by symbols.

NOTE The computer programmer needs to use Boolean algebra when


working at machine-language level. This kind of programming needs
extensive knowledge of the actual hardware of the computer, and
Boolean algebra is the most convenient method of description.

3.3 Boolean algebra: symbols and conversions

The logical operators: AND, OR, NOT determine the relationship between
binary variables and are represented by the following symbols:

 The AND operation is indicated by a dot (.) or by writing the letters with no
spacing in between: X.Y is the same as XY because both mean X AND
Y.
 The OR operation is indicated by the (+) sign: X + Y means X OR Y.
 The NOT operation is indicated by a (') next to a variable or by a bar or
vinculum over a variable: X' is the same as because both mean X
NOT.

Variables are grouped together to retain the identity of the gate, and indicate
the intended function by using the grouping symbols shown in Table 3.1.

Table 25 - Boolean algebra grouping symbols


Boolean
algebra Symbol Priority
grouping
First priority when writing an equation from a logical
diagram.
Parentheses ()
Last priority when developing logical diagrams from
equations.
Second priority when writing equations from logical
Brackets []
diagrams or developing diagrams from equations.
Third priority when writing an equation from a logical
diagram.
Braces {}
First priority when developing logical diagrams from
equations.
__ The vinculum represents NOT and can also be used as
Vinculum a grouping symbol in place of any of the others where
applicable.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 55 of 170
3.4 Development of equations from logical diagrams

3.4.1 First level logic


First level logic (one symbol) does not require signs of grouping.

A A
C B C
B

AB = A+B=
C C
Figure 3.1 – First level logic

Figure 3.1 shows the first level logic.

 The expression AB = C can be read as: if inputs A and B are present at the
same time, there is an output of C. Further, this output exists only for the
duration of time that both inputs are present.
 The expression A + B = C can be read as: if any one or both of the inputs
are present, then there is an output of C. Further, this output exists as long
as any one of the inputs is present.

3.4.2 Second level logic


 Grouping becomes important when working with logic diagrams that are
compounded by having an AND circuit feeding an OR circuit or vice versa.
 The diagrams below show the signs of grouping, and how they will be used
when one logic gate feeds another.
 Notice the signs of grouping in three of the four diagrams. In the fourth case
grouping signs are not necessary.

The only time signs of grouping are not necessary is when an AND gate feeds
an OR gate.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 56 of 170
Figure 3.2 – Second level logic

 Figure 3.2 makes use of the Boolean algebra grouping symbols discussed in
Table 25.
 In diagram A, parenthesis is used to group AB. This then means that when
writing the expression from diagram A, that AB takes priority over C. The
same priority of parenthesis will apply in diagrams B, C, and D.
 The output gate of both B and D above is an OR function, thus, the term
overall OR function is applied to these logic diagrams.
 Similarly, A and C are overall AND function diagrams.

NOTE There should be a maximum of 2 inputs into a gate. Where there is no


formal grouping, e.g. A + B + C, you may form your own groups of 2,
commonly done from left to right - i.e. A + B + C could be grouped as
(A + B) + C.

3.4.3 Third level logic


 Diagram A in Figure 3.3 illustrates two AND gates feeding an OR gate which
in turn feeds another OR gate. Note the lack of signs of grouping within the
expression, and that parentheses are used first.
 Diagram B in Figure 3.3 illustrates two OR gates feeding an AND gate which
in turn feeds another AND gate making the diagram an overall AND
function.
 In this case, signs of grouping are used to retain the circuit identity.
 Again, parentheses are the first signs of grouping used, followed by
brackets.
 In both cases the Boolean equation was written starting at the input, on the
left side, and working one step at a time through the complete logic
diagram writing the Boolean equation after each step.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 57 of 170
Figure 3.3 – Third level logic

 Figure 3.3 uses a different priority from Table 3.1. Here parenthesis is used
as well as square brackets.
 This means that when writing an expression from diagram B, A + B and D +
E will be grouped first using parenthesis and only then will (A + B) and (D +
E) be grouped using square brackets ([ ]). Therefore, we say that square
brackets take second priority and not first like parenthesis.

3.4.4 Fourth level logic


Figure 3.4 illustrates fourth level logic and is an overall AND function.

 The first step in writing the equation results in A + B as the output of gate
one.
 The second step results in (A + B) C as the output of gate two.
 The third step should be to write the output of gate three which is D + E.
 The fourth step results in combining the inputs to AND gate four, to show
one output by making sure each input is separate.

In this case, brackets are required for one input and can also be used on the
other input to show equality and for ease of reading.

 The final step is to combine the inputs to AND gate five resulting in the
output using braces for one of the inputs.
 Braces can also be used around the single letter F on the output equation to
show equality, but understand they are not required.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 58 of 170
Figure 3.4 – Fourth level logic

 In Figure 3.4, another Boolean algebra grouping symbol from Table 3.1 is
added to the expression. Here, curly brackets are used together with
parenthesis and square brackets. When writing an expression from the
above diagram, A + B will be grouped first using parenthesis (1st priority),
then (A + B) C and D + E will be grouped using square brackets (2nd
priority), and lastly [(A + B) C] [D + E] will be grouped using curly brackets
(3rd priority).

3.4.5 The law of NOT


The NOT function is unique to Boolean algebra. It is indicated by a vinculum
̅ or A'.
( ̅ ) over a symbol, or an apostrophe (') e.g.A

 The word NOT indicates:


o the converse of,
o alternate value of,
o complement of,
o or the opposite of either the symbol or the functional sign.

 For example, 0 ̅ or 0' (zero NOT) is equal to 1, for if it is not 0, the only
other value it can have is one.
 Conversely, 1 ̅ or 1' (1 NOT) can only be equal to 0.
 It follows, then that if a variable A is not 1, the only other value it can have
is 0.
 When the NOT function is applied to a logical connective the connective
assumes the alternate function, for example, + ̅ (OR NOT), becomes AND,
and .̅ (AND NOT) becomes OR.
 The vinculum also acts as a grouping sign and is substituted in place of
parentheses, brackets, or braces when a state indicator is on the output of
any given logic symbol.
 In some instances, a signal or sign may be negated more than once.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 59 of 170
 It may have a double negation or a triple negation, or even more as shown
in Figure 3.5.
 If there is an even number of vincula over the variable, it can be reduced
to equal the variable itself.
 If there are an odd number of vincula over the variable the value is equal to
the negation of the variable.
 Table 26 depicts the truth table of A.

Figure 3.5 – Show even/odd number of vincula

Table 26 – Truth table for NOT


Truth table
A A' A'' A'''
1 0 1 0
0 1 0 1

3.4.6 Logic diagram with state indicators


Figure 3.6 includes state indicators at inputs A and C. The logic diagram below
shows that to satisfy these gates, the signals A and C must be inverted.

̅ B + C̅ = Z.
Therefore, the equation for this diagram is: A

Figure 3.6 – Boolean and state indicators of inputs

3.4.7 State indicators on outputs


 In writing the Boolean equations of symbols with the state indicators on the
output, all signals and signs preceding the state indicator will be under a
continuous vinculum as shown in Figure 3.7.
 Note that the vinculum also acts as a means of grouping, making any other
signs of grouping unnecessary.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 60 of 170
Figure 3.7 – Grouping for state indicators

 Remember, that a logic operation that will produce an output when either
input is present, but not when both inputs are present is called an
exclusive OR. See Figure 3.8.

Figure 3.8 – Exclusive OR logic symbol and equation

 The exclusive OR operation is not a basic logical operation because it can


be accomplished by a combination of the AND, OR, and NOT functions as
shown in Figure 3.9.

Figure 3.9 – Combination of AND, OR and NOT

 By writing the Boolean equation for the above circuit, the exclusive OR
equation is developed.

 The equation, A'B + AB' = C, simply means NOT A AND B, OR A AND NOT B
equals C. In other words, NOT both inputs at the same time.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 61 of 170
3.4.8 Converting logic diagrams to Boolean equations
Upon completion of this activity you should be able to write a Boolean equation
to describe the output of a logic diagram of four levels.

 Step-by-Step 1

 Start with input signals and develop terms until the output is reached.
 X and Y feed gate 1, the output is: XY.
 S and T feed gate 2, the output is: ST.
 The inputs to OR gate 3 is: XY, ST, giving the output expression: XY + ST.

 Step-by-Step 2

 Start with the input signals and develop terms until the output is reached.
 T and U feed OR gate 1, the output is: T + U, inverted to give ̅̅̅̅̅̅̅̅
T+U
 X and Y feed OR gate 4, the output is: X + Y.
 Z is inverted, giving us .
 The inputs to AND gate 3 is: X + Y and , giving us .

 The whole lot is inverted, giving us: .

 Gate 2 ORs the two together to give us the output expression:

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 62 of 170
3.4.9 Converting Boolean equations to logic diagrams
Table 3.3 contains the rules for converting a Boolean to a logic diagram.

Table 27 - Rules for converting a Boolean to a logic diagram


Rule 1  If the complete expression is under a vinculum, draw the state
indicator for the output of the gate.
 Start with the highest level sign of grouping for the expression.
 Do not start with signs that are within other signs.
Rule 2  Determine the overall function of the expression.
 One sign is always exposed (not included in any bracket or
vinculum).
 This tells the function of the previous gate.
 Exposed OR signs have priority over exposed AND signs.
Rule 3  Draw the symbol that represents the overall function of the
expression.
 Show one input for each term of the overall function.
 Remove signs of grouping one set at a time, starting with the
highest level and working down.
NOTE: The above rules apply to each variable in an expression.

 Simple equations, such as: ABCD = X or A + B + C + D = X poses no


problem.
 They are immediately recognised as a single, four-input AND gate, and a
single four-input OR gate.
 Likewise the equation (A + B) (C + D) = X should offer little challenge. The
equation states that one quantity (A + B) AND another quantity (C + D) is
equal to X. It is therefore an overall AND function.
 Within one set of parentheses is A + B, which is a two input OR gate that
supplies the overall AND gate, and C + D is also a two input OR gate as
the other supplier to the output AND gate. This logic diagram is shown in
Figure 3.10.

Figure 3.10 - Multiple Input Overall AND Function

Step-by-Step (Boolean equations to logic diagrams)

Let us look at a more complex equation:

 Step 1 a. Identify the overall circuit.


b. The OR sign is not enclosed, therefore it is an overall OR function.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 63 of 170
c. Determine the number of inputs to the OR gate by dividing the
equation at each OR sign that is not enclosed. There are two inputs
in this instance as shown below.

 Step 2 a. Perform the simplest operation first: Observe AB + CD, and again
determine the circuit.
b. D and AB + C are the inputs.
c. Draw a two-input AND gate 2 as the supplier to the OR gate as
shown below.

 Step 3 a. Remove the vinculum from the equation .


b. The vinculum over signals and signs indicates the output of that
gate is taken through a state indicator. Nothing under the vinculum
can be separated until the vinculum has been removed.
c. The exposed OR sign (after the vinculum is removed) indicates a
two-input OR gate 3 as shown below. Whenever possible, draw a
state indicator on the output of a gate rather than on the input
[rather put the state indicator on the output of OR gate 3, use a
NOT symbol on an input ONLY when it is a single input].

 Step 4 Input AB is the last input to be shown. A and B are the inputs to AND
gate 4 as shown below.

 Step 5 a. Proceed to the second input of the output gate 1: [F (G + H) + I].


b. Remove the brackets.
c. Divide the equations at each OR sign not enclosed.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 64 of 170
d. Draw the input OR gate 5 as shown below

 Step 6 Divide F (G + H) into two inputs and draw AND gate 6 with
Parentheses removed as shown below.

 Step 7 Note that G + H is an OR gate and add it as the last symbol.


This completes the second input to OR gate 1, and also completes the
diagram as shown below.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 65 of 170
3.5 Key terms

 Logic diagram
 State indicator
 Boolean equation

3.6 Exercises

1. Write the Boolean equation for each of the following logic diagrams.

A. ________________________
B. ________________________

A B

2. The following logic diagram is an overall ______________ function.

3. Write the Boolean equation for each of the following:

4. Write the output equation for the following logic circuit.


Label the output expression after each logic symbol.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 66 of 170
NOTE The level of logic is limited only by the equipment involved, and
some logic diagrams become quite complex. To add to the
complexity of the diagram, there is the inverter, which leads to the
law of NOT.

5. If B = 1 and B has been negated twice (B) then B is equal to _________.

6. Write the Boolean expression for the output of the following diagram.

7. Write the output Boolean expression for the following logic symbols.

a. b.

8. In reference to the following symbol, write the output expression as it would


be said aloud. __________________________

9. Draw the circuit symbol for the equation 𝐴𝐵̅ 𝐶̅ .


10. Write the output expression for the following logic circuit.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 67 of 170
11. Write the output expression for the following logic circuit.

12. What Boolean expression represents the output of this logic diagram?
Label the output of each logic symbol.

13. Write the Boolean equation for the following symbol.

14. Write down the output expressions for the logic functions below.

a.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 68 of 170
b.

c.

d.

e.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 69 of 170
3.7 Revision questions

1. Draw the logic diagrams for the following Boolean expressions:

a. (L + M + N) O + P

b. D' + E + F' (G + H)

c. (A + B) (A'CD + E)'

̅ D} ̅̅̅̅̅̅̅̅
d. {(A + B)C G+H

e. [(RS̅ + R
̅ S ) U] [ ( W + X
̅)Y]

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 70 of 170
Unit 4 - Using Boolean Algebra

At the end of this unit you will be able to:

 Identify Boolean laws and theorems.

4.1 Boolean algebra: laws and theorems

 It is very important to study the following laws and theorems thoroughly, as


they form the basis of all Boolean algebra.
 Just as ordinary algebra is simplified by means of basic theorems,
expressions describing a given switching circuit network or logical diagram
may also be reduced or simplified.
 This enables the logic designer to simplify the circuitry used in achieving
economy of construction and aiding in troubleshooting.
 The following laws and theorems are essential to solving problems involving
Boolean algebra. Therefore, it is important for you to know them, and be
able to recognise when to apply them.
 There are eight main groups of laws of Boolean algebra and one important
theorem.

NOTE In the laws and theorems that follow, x is used to represent any
variable or expression.

Therefore: x + 0 = x

Also means: y + 0 = y
xy + 0 = xy
(x + y) + 0 = (x + y)

In other words, any variable or expression ORed with 0 is equal to itself.

This is the first law of Identity and like all the others, can be proved by building
a truth table. The truth table for x + 0 = x is shown in Table 4.1.

Table 28- Truth table for x + 0 = x


x x+0 Result
0 0+0 0
1 1+0 1

The truth table proves when x is zero, the result is zero, and when x is 1, the
result is 1. Table 29 lists all the laws and theorems.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 71 of 170
Table 29 - Boolean laws and theorems
Any variable or
Rule Examples
expression…
Identity …ORed with 0 is equal to
x+0=x
itself
…ANDed with 1 is equal
x.1=x
to itself
…ORed with 1 is equal to
x+1=1
1
…ANDed with 0 is equal
x.0=0
to 0

Idempotence …ORed with itself is


x+x=x
equal to itself
…ANDed with itself is
x.x=x
equal to itself

Complement …ORed with its


x + x' = 1 complement is equal to
1
…ANDed with its
x . x' = 0 complement is equal to
0

Involution (x')' = x

Commutative x+y=y+x
x.y=y.x

Associative (x + y) + z = x + (y+ z)
x . (y . z) = (x . y) . z

Distributive x . (y + z) = x . y + x . z
x + y . z = (x + y) . ( x + z)

Absorption x+x.y=x
x . (x + y) = x

De Morgan's (x + y + z …)' = x'.y'.z'…


theorem (x . y . z …)' = x'+y'+z'…

Simplification A + A'B' = A + B'


Theorem A' + AB = A' + B

NOTE These laws can be used to reduce Boolean equations the simplest
form possible. In the real world, this means reducing cost, because
every logic operator represents a corresponding element of hardware.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 72 of 170
You may find the following grouping of the laws a little easier to remember.

AND LAWS OR LAWS


x.0=0 x+0=x
x .1 = x x+1=1
x.x=x x+x=x
x . x’ = 0 x + x’ = 1
xy = yx x+y=y+x
(xy) z = x (yz) (x + y) + z = x + (y + z)
x + yz = (x + y)(x + z) x (y + z) = xy + xz
x (x + y) = x x + xy = x
(xy)’ = x’ + y’ (x + y)’ = x’ y’

The techniques used to reduce Boolean equations are similar to those used in
ordinary algebra. Here is a suggested general approach:

 Multiply all variables necessary to remove parentheses.

 Look for identical terms and drop one:


x.x = x and x + x = x

 Look for a variable and its complement in one term and drop the term:
xx’y = 0.y = 0

 Look for pairs of terms that are identical, except for one variable.
If one variable is missing, the larger term can be dropped:
abcd + abd
= abd(c + 1)
= abd.1
= abd

 Try to prove the above laws and theorems for yourself.


 Here is an example of how the Absorption law would be proven:

x+ x.y
=x. 1+x.y Identity: x . 1 = x
=x. (1 + y) Distributive Law
=x. 1 Identity
=x Identity

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 73 of 170
Further examples using Boolean algebra:

1. Simplify: A'B'(A' + B')(B' + B)

Expression Rule(s) used


A'B'(A' + B)(B' + B) Original expression

A'B'(A' + B)(1) Complement


(A + B)(A' + B) De Morgan; Identity
AA' + AB + A'B + BB Distributive
AB + A'B + B Complement; Identity; Idempotence
B(A + A' + 1) Identity
B

2. Simplify: (A + C)(AD + AD') + AC + C

Expression Rule(s) used


(A + C)(AD + AD') + AC + C Original expression

(A + C)(AD + AD') + C(A + 1) Distributive


(A + C)(AD + AD') + C Identity
(A + C)[A(D + D')] + C Distributive
(A + C)(A) + C Complement, Identity
AA + AC + C Distributive
A + AC + C
A+C Idempotence; Absorption

3. Simplify: A'(A + B) + (B + AA) (A + B')

Expression Rule(s) used


A'(A + B) + (B + AA)(A + B') Original expression

A'(A + B) + (B + A)(A + B') Idempotence


A'A + A'B + AB + BB' + AA + AB' Complement; Idempotence; Identity
A'B + AB + A + AB' Absorption
A'B + AB + A Distributive
B(A' + A) + A Complement
B+A

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 74 of 170
4.1.1 Boolean functions
 As in arithmetic expressions, brackets may be used to indicate the order of
evaluation of the operations.

NOTE A Boolean function is an expression formed using Boolean variables,


the binary operators AND and OR, and the unary operation called
NOT.

 There is an agreed order of evaluation, namely: the expression/s in


brackets first, then NOT, then AND, then finally OR.

BRACKETS - NOT - AND - OR

4.2 De Morgan's theorem

When dealing with De Morgan's theorem, it is important to remember that the


vincula, in this case also referred to as 'the bar', is a separate Boolean algebra
grouping symbol (as seen in Table 3.1).

De Morgan's theorem may be thought of as breaking 'the bar' symbol. When


the bar is broken, the operation directly underneath the break changes from
addition to multiplication, or multiplication to addition, and the remaining bar
piece stays over the individual variables. The following illustrates this concept.
De Morgan's laws state:

Figure 4.1 – NOR to Negative-AND

Figure 4.2 – NAND to Negative-OR

The number of variables that may be 'broken' is unlimited:

Figure 4.3 – Multiple NOR to Negative-AND

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 75 of 170
From De Morgan's two laws, you can deduce the following rule:

Whenever you split or join vincula, change


AND to OR / OR to AND

 If a vinculum covers part of an expression, only the signs under the


vinculum change. The signs outside the vinculum do not change.
 When numerous 'layers' of bars are present in an expression, it is easiest to
remove the longest bar first, i.e. the uppermost bar. It is also important
that only one bar be broken at a time.
 Whenever an even number of vincula are joined or split, the sign stays the
same. When an odd number of vincula are joined or split, the sign changes.
See Figure 4.4.

Step 1 Step 2

Step 3

Figure 4.4 – Changing signs

 When you change signs, preserve grouping: becomes


 An expression is in its simplest form only if all letters have no more than
one vinculum over them.

De Morgan's theorem may be illustrated using the following truth tables:

A B A B
0 0 1 1 0 0 1 1
0 1 1 1 0 1 0 0
1 0 1 1 1 0 0 0
1 1 0 0 1 1 0 0

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 76 of 170
From the above truth tables it can be seen that:

 and are equal for all combinations of 0 and 1 inputs.


 and are equal for all combinations of 0 and 1 inputs.

Two ways of simplifying an expression using De Morgan's theorem:

 Join vincula to form the complement of a term or expression.


 Split all vincula and apply other laws for further simplification.

Here are some examples.

1. Join the vincula.

Given the expression:


is not in its simplest
form.

Apply De Morgan’s: (join the vincula) Unless an expression can


be manipulated so that one
part is the complement of
the other, use De Morgan’s
This gives the complement of RS: theorem to split all vincula.

To simplify: split
the long vinculum to give
This may be simplified by the law of the following:
uniqueness to:

The expression can be


This may be simplified by the law of simplified:
identity as:

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 77 of 170
2. Split the vinculum.

Given the expression: For a more complex expression


like:

Apply De Morgan’s: (split the vinculum)


The above method would take
many steps.

May be simplified by the law of It is easier to simplify more


uniqueness to: complex expressions by
removing the vincula and
changing the sign if there are
an odd number of vincula.
And by the law of identity to:

=
This is equal to:
The sign stays the same when
there is an even number of
vincula.

Further examples using De Morgan's to split or join vincula:

3. =

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 78 of 170
4. use De Morgan's to split the long vinculum

= apply laws: x.x' = 0, xy = yx

= 0 + BC.BC apply law: x.x = x

= 0 + BC apply law: 0 + x = x

= BC

A quick method for simplifying more complex expressions works by:

 Considering each letter and each sign on its own by putting them in
separate columns and applying De Morgan's theorem.
 Then writing the simplified expression one letter and one sign at a time.

Figure 4.5 – A quick method for simplifying expressions

Let us look at De Morgan's theorem in terms of logic circuit diagrams.

Figure 4.6 – The NOR gate equals the AND gate with inverted inputs

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 79 of 170
Figure 4.7 – The NAND gate equals the OR gate with inverted inputs

4.3 Key terms

 Boolean algebra
 De Morgan's theorem
 Boolean functions
 Vinculum

4.4 Exercises

1. Showing all the steps, reduce the following equations to their lowest form.
a. F = (ab)(cd')(a')
b. F = xzy + xzy' + x'z
c. F = ab'c + ac'(b + a') + a'b'c
d. F = xwy' + z'yxw + wxyz + yx'zw
e. F = AB'C + AB'C' + ABC' + ABC + A

2. Apply De Morgan's theorem to the following expressions.


a. ̅̅̅̅̅̅̅̅̅̅̅̅
J+K+L
b. ̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
̅ + S̅ + T
R ̅+U ̅ Whenever When you
you split or change signs,
c. join vincula, keep original
d. change the grouping of
sign: letters. e.g.
e.
AND to OR,
OR to AND.
3. Using De Morgan's theorem and Boolean algebra laws, show all the steps to
do the following.
a. Simplify [W'X' + Y] [Y'(W + X)] + Z.
b. Prove the following Simplification Theorem – A + A'B' = A + B'.
c. Prove X'Y'Z' + XY'Z + X'YZ' + XYZ' + XYZ = X'Z' + XZ + XY
d. Prove AB + (A' + B')CD = AB + CD
e. Prove A + B + CD + (AB)' = 1
f. Prove XY'Z + XYZ' + XYZ = XY + XZ

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 80 of 170
4.5 Revision questions

1. George Boole developed a mathematical system of ___________ to express


_______ _________ as symbols, and then manipulate these symbols to
arrive at a conclusion.

2. Boolean algebra equations can represent any device that has


____________ conditions.

3. Boolean algebra developed with computer advancements has proven to be


a great asset in both ___________ and _____________.

4. In Boolean algebra, symbols are used to represent logical


_______________.

5. The symbol for an AND operation in Boolean algebra is a ____________ or


the letters can be written with ____________ between them as in
multiplication for ordinary algebra.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 81 of 170
Unit 5 - The Karnaugh Map

At the end of this unit you will be able to:

 Determine the minterms of a Boolean expression.


 Draw Karnaugh maps for up to four variables.
 Read Karnaugh maps to reduce Boolean expressions.

5.1 Introduction to the Karnaugh map

A Karnaugh map provides a graphic method of simplifying Boolean algebraic


expressions. Think of the Karnaugh map as another form of truth table.

Before we can discuss Karnaugh maps further, we need to define what is


meant by a minterm and how to express those using decimal numbers.

 One of the most powerful theorems within Boolean algebra states that any
Boolean function can be expressed as the sum of products of all the
variables within the system.
 For example, A + B can be expressed as the sum of several products, each
of which contains the letters A and B. Similarly, in a three-variable
expression, each product must contain all three variables and in a four-
variable expression each product must contain all four variables.
Remember to arrange them in alphabetical order.
 These products are called MINTERMS.

For example, we can convert A + B to minterms in the following way.

A+B
= A (1) + B (1) [x.1 = x] – anything AND 1 is equal to itself.
= A (B + B') + B (A + A') [x + x' = 1] – anything Ored with its
complement = 1
= AB + AB' + AB + A'B [multiply out and re-sort into alphabetical
order]
= AB + AB' + A'B [drop redundant terms]

The terms AB, AB', A'B are the minterms of A + B.

 The above process is called EXPANSION.


 Note that each minterm contains all the letters used: A and B.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 82 of 170
 Because minterms must contain all the letters used, a shorthand notation
has been developed that saves time writing down the letters. This can be
done in two easy steps:
Form a binary word out of the letters by substituting a 0 for any NOTed
letter and a 1 for the rest.
5. Then express the minterm as the decimal equivalent of this binary word
using an 'm' to show that it is a minterm.

We can convert AB, AB', A'B to decimal minterms as follows:

AB [write the original term]


11 [form binary word by substituting zeros for NOTed terms and ones for
the rest]
m3 [express the minterm as a decimal equivalent of the binary word]

AB' ▬► 10 ▬► m2
A'B ▬► 01 ▬► m1

Therefore: AB + AB' + A'B = m3 + m2 + m1

The Karnaugh map is a diagram made up of squares that each represents a


minterm of the expression being simplified.

Table 30- Ratio of variables to minterms


Number of variables in Number of minterms
expression
1 2
2 4
3 8
4 16

A Boolean function may be indicated by marking the appropriate squares in the


map. For example:

Figure 5.1 – Boolean functions on a Karnaugh Map

Figure 2.1 shows Venn diagrams for the AND, OR, and NOT logic operators and
the shaded areas in these diagrams can be compared to the marked squares.
The square for x AND y is that square in which both x and y are represented.
The squares for x OR y are all those squares where either x, or y, or both x
and y are represented.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 83 of 170
5.2 Basic shapes of the Karnaugh map

Before we examine the various Karnaugh maps in detail, let us look at their
basic shapes. The shaded sections of the maps show the blocks that represent
the variable indicated.

Figure 5.2 – The one variable Karnaugh map

Figure 5.3 – The two-variable Karnaugh map

Figure 5.4 – The three-variable Karnaugh map

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 84 of 170
Figure 5.5 – The four-variable Karnaugh map

Now that you know what the maps look like, we can look at how to construct
them in more detail.

NOTE In this section that follows, we have used the variables w, x, y, z –


but any series of variables could be used such as: a, b, c, d. As you
look through the examples, think of the w, x, y, z as being the first,
second, third, or fourth-variable in any given series.

 Karnaugh maps are effective for reducing an expression to a sum-of-


products form.
 Karnaugh's map reduction is based on the fact that minterms in adjacent
squares can be simplified or reduced because they differ by only one
variable. This is true for every horizontally and vertically adjacent pair on
the map.
 This is also true of combinations formed by 'wrapping' the map around
horizontally or vertically. In other words, Karnaugh maps conform to the
Gray code system in which each successive term differs by only one
variable either horizontally or vertically.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 85 of 170
NOTE The order of the variable is very important. For the sake of simplicity,
it is easiest to keep the variables in alphabetical order – e.g. defg or
wxy, etc. When drawing the four-variable Karnaugh map, the first
variable is always placed on the left-hand side, the second on the
right-hand side, the third on the top, and the fourth on the bottom of
the map.

Example: In a four-variable Karnaugh map, A'B'C'D' and A'BC'D' represents


the minterms 0000 and 0100 or m0 and m4 which are vertically adjacent.
These adjacent minterms can be reduced as follows:

This solution can be read directly from the map by grouping m0 and m4, and
by noting the variables represented by the blocks into which both minterms
fall.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 86 of 170
Figure 5.6 – Wrapping and Karnaugh map minterms

Rules for Grouping

Arrange adjacent squares in groups of 2, 4, 8 or 16.

6. Groups can be formed horizontally or vertically.

7. Make groups as large as possible.

8. Always include at least one minterm not grouped before, when forming a
new group.

9. Once every minterms belongs to at least one group, stop grouping.

Now let us look at one-, two-, three-, and four-variable Karnaugh maps in a
little more detail.

5.2.1 The one-variable Karnaugh map


For a function with one variable, x, there are two minterms. The Karnaugh
map consists of two squares:

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 87 of 170
Minterms are: x, x' or binary minterms 0, 1 or decimal minterms m0, m1.

5.2.2 The two-variable Karnaugh map


For a function with two variables, x and y, there are four minterms. The
Karnaugh map will be:

This gives the minterms: x'y', x'y, xy', xy OR


Binary minterms: 00, 01, 10, 11 OR
Decimal minterms: m0, m1, m2, m3

Let us look at using Karnaugh maps to simplify expressions using two


variables:
For example, simplify:

F = A'B + B'A + A'B' [no need for expansion, each product contains A and
B]
= A'B + AB' + A'B' [re-sort into alphabetic order]
= 01 + 10 + 00 [change to binary terms]
= m1 + m2 + m0 [write minterms – binary to decimal]

Now map the terms:

Group adjacent squares: [i.e. any two squares that share a boundary – this
includes the top and bottom edges and the left and right edges.]

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 88 of 170
NOTE It is possible to use the same square twice because anything ORed
with itself is equal to itself. The law of idempotence says: x + x = x

Read the map to reduce the number of terms by writing down the least
number of terms that are required to label each group unambiguously.

m0 + m1 = A'
m0 + m2 = B'

The simplified expression is then the logical OR of all the terms needed to
identify each group. Therefore: F = A' + B'

5.2.3 The three-variable Karnaugh map


For a function with three variables: x, y and z, there are eight minterms. These
maps are laid out as follows:

This gives the minterms: x'y'z', x'y'z, x'yz, x'yz', xy'z', xy'z, xyz, xyz' OR
Binary minterms: 000, 001, 011, 010, 100, 101, 111, 110 OR
Decimal minterms: m0, m1, m3, m2, m4, m5, m7, m6

Now let us look at how you would use a Karnaugh map to solve a three-
variable Boolean expression.

Example 1. Simplify: F = AB'C + ABC + A'B'C' + A'BC'

NOTE All three variables are present in each product, so no expansion is


necessary.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 89 of 170
1. First draw your Karnaugh map.
As there are three variables, there will be a maximum of eight minterms and
therefore the map will be made up of eight blocks.

2. Use the given variables to label the columns and rows.

3. Put the product terms in the appropriate blocks


F = AB'C + ABC + A'B'C' + A'BC'

4. Convert to binary by substituting a 1 for ordinary variables and a 0 for


NOTed variables.

5. Convert to decimals and express as minterms.

6. Group the minterms in adjacent squares and write down the variables that
represent the group/groups formed, and then OR the terms representing each
group.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 90 of 170
We group m5 and m7 because the corresponding squares are adjacent and
differ in only one variable. We group m0 and m2 because they are adjacent if
we 'wrap' the map. Again they differ by only one variable.

7. From the grouping we can read that:


m5 + m7 = AC and m0 + m2 = A'C'

We now OR the results of the two sets of minterms together to get the result.
Therefore, the simplified version of the original expression:

F = AB'C + ABC + A'B'C' + A'BC' is: F = AC + A'C'

The map reduction is possible because as a general rule: Any two minterms
in adjacent squares that are ORed together will remove the different
variable.

From the above example:

m5 + m7 = AB'C + ABC = AC (B' + B) = AC [B is removed]


m0 + m2 = A'B'C' + A'BC' = A'C' (B' + B) = A'C' [again B is removed]

We can prove our map reading was accurate by using Boolean algebra.

F = AB'C + ABC + A'B'C' + A'BC'


= (AB'C + ABC) + (A'B'C + A'BC')
= AC (B' + B) + A'C' (B' + B)
= AC + A'C'

Example 2. Simplify: G = A'C + A'B + AB'C + BC


First we expand the products so that each variable is represented.

G = A'(B + B') C + A'B(C + C') + AB'C + (A' + A) BC


= A'BC + A'B'C + A'BC + A'BC' + AB'C + A'BC + ABC [remove redundant
terms]
= A'BC + A'B'C + A'BC' + AB'C + ABC

Now draw and label the map, filling in the terms.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 91 of 170
Now convert terms to binary and decimal minterms and group terms in
adjacent squares.

Then OR terms representing each of the groups. In this case we have a group
of four squares all represented by C and a group of two squares represented
by A'B. Therefore, our simplified expression is: G = C + A'B. You can use the
same square twice if at least one term in the new group has not been used
before because xyz = xyz + xyz.

5.2.4 The four-variable Karnaugh map


For a function with four variables: x, y, z, and w, there are sixteen minterms.
These maps are laid out as follows:

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 92 of 170
This gives the minterms: w'x'y'z' w'x'y'z w'x'y z w'x'y z'
w'x y'z' w'x y'z w'x y z w'x y z'
w x y'z w x y'z wxyz w x y z'
wx'y'z' w x'y'z w x'y z w x'y z' OR

Decimal minterms: m0, m1, m3, m2 m4, m5, m7, m6, m12, m13, m15, m14,
m8, m9, m11, m10, respectively, OR

Binary minterms: 0000, 0001, 0011, 0010, 0100, 0101, 0111, 0110, 1100,
1101, 1111, 1110, 1000, 1001, 1011, 1010, respectively.

Example 1. Simplify the expression: F = AB'CD' + AB'CD + ABCD' + ABCD

NOTE All four variables are present in each product, so no expansion is


necessary.

1. Convert the expression to binary minterms:


1010 1011 1110 1111

2. Convert to decimal minterms:


m10 m11 m14 m15

3. Draw your map. There are four variables, so we know there will be a
maximum of 16 minterms and therefore the map will be made up of 16
blocks.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 93 of 170
4. Use the given variables to label the columns and rows.

5. Put either the product terms of the binary or decimal minterms in the
appropriate blocks. Here we will insert the product terms in the appropriate
blocks.

6. Group adjacent blocks and write down the variables that represent the
group/groups formed, then OR the terms representing each group. In this
case, the one group of four is represented by AC. Therefore F = AC.

We can prove our map reading algebraically:

F = AB'CD' + AB'CD + ABCD' + ABCD


= AB'C (D' + D) + ABC (D'+ D)
= AB'C (1) + ABC (1)
= AB'C + ABC
= AC (B'+B)
= AC (1)
= AC

Therefore F = AC, which is exactly the same as the answer obtained through
reduction using our Karnaugh map!

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 94 of 170
Example 2. Simplify: F = A'B'C' + B'CD' + A'BCD' + AB'C'

1. Expand products to include all four terms

F = A'B'C'(D + D') + (A + A') B'CD' + A'BCD' + AB'C'(D + D')


= A'B'C'D + A'B'C'D' + A'B'CD' + AB'CD' + A'BCD' + AB'C'D + AB'C'D'

2. Convert the terms to binary then decimal minterms


Binary minterms: 0001 0000 0010 1010 0110 1001 1000
Decimal minterms: m1 m0 m2 m10 m6 m9 m8

3. Draw and fill in the map

4. Group adjacent terms


 m0, m1, m8, m9 form a four square by wrapping the map horizontally,
reducing to B'C'.
 m0, m2, m8, m10 form another four square, reducing to B'D'.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 95 of 170
 Finally, m2 and m6 are adjacent if we use m2 a second time, giving the
term A'CD'
5. OR the terms to give the simplified expression:
F = B'C' + B'D' + A'CD'

NOTE Karnaugh maps for more than four variables are difficult to handle
and are not covered in this module.

5.3 Key terms

 Karnaugh map
 Minterms
 Expansion
 Binary terms

5.4 Exercises

1. Simplify the following equations by using a Karnaugh map. Derive your


binary and decimal minterms before plotting the map. Show all working.

a. F = ABC + AB'C + AB'C'


b. F = A'B'C + A'BC + ABC' + ABC
c. F = XYZ' + X(Y + Y') + ZX
d. F = PQ'R + QR + P'Q'R + PQR'
e. F = X'Y'Z' + XY'Z + X'YZ' + XYZ' + XYZ
f. F = QP(R'S' + RS') + R (SPQ + SPQ')
g. F = J'K'L'M' + MLK + K'L'M' + JK'L
h. F = AB'C + ABD + AB'D + A'CB

5.5 Revision questions

1. Expand the following expressions so that each product contains all the
variables:

a. A'B + C
b. AB + C'D +AB'C
2. Express the following products in binary and decimal minterms.

a. AB'C
b. AB'CD'
c. ABC'D'E

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 96 of 170
Unit 6 - Decision Tables

At the end of this unit you will be able to:

 Understand how to use decision tables.


 Identify conditions and actions.
 Construct your own decision table.
 Determine impossible rules on a decision table.

A Systems Analyst is responsible for developing, implementing, and updating


information systems. The analyst is also responsible for supplying the decisions
a program must make, as well as the actions to be performed as a result of
these decisions. This information can be given to the programmer in the form
of a decision table, which is a more effective form of communication than a
written explanation.

6.1 The elements of decision tables

A decision table is a graphical illustration of actions to be performed, based on


a set of logical conditions. Decision tables present the decision possibilities and
resulting actions in a compact form that can be interpreted easily. All
branching possibilities, which must be considered by the programmer in the
coding of a computer program, are indicated on a decision table.

6.1.1 Decision table example


A student must answer three questions to determine on which page the
student must begin working through a computer-based lesson.

The procedure could read as follows:

When the student has Start studying on page


correct answer for
All three 40
None 20
A and B 30
B and C 35
A and C 35
A 25
B 25
C 25

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 97 of 170
This would be represented on a decision table as follows:

Table 31 - Decision table example


TITLE LEARNER PROGRESSION TABLE
TABLE SIZE 3C, 5A, 8R

1 2 3 4 5 6 7 8
C1 IS A CORRECT? Y Y Y Y N N N N
C2 IS B CORRECT? Y Y N N Y Y N N
C3 IS C CORRECT? Y N Y N Y N Y N

A1 GO TO P 20 X
A2 GO TO P 25 X X X
A3 GO TO P 30 X
A4 GO TO P 35 X X
A5 GO TO P 40 X

The decision table in Table 6.1 has the following elements:

 Title (an identifying description of the table as a whole). In the above


example, the title of the table is 'Learner progression table'.
 Table size (the number of conditions, actions, and rules the table
contains). The above example has three conditions, five actions, and eight
rules.
 Conditions (factors the computer must test to make a decision). A
condition statement consists of a stub (the left side of the statement) and
entries (the right side of the statement). An entry is either Y (yes) or N
(no).
 Actions (actions to be taken as a result of existing conditions). An action
statement also consists of a stub and entries. An action can either take
place (represented by X) or not take place (blank square). If one considers
rule 1 in the above example, A, B and C are all correct and X will be placed
next to Go to p 40.
 Rules A rule is a unique combination of (i) one entry for each condition and
(ii) the resulting action or actions. A rule forms a vertical column of
squares. The number of rules is determined by the number of conditions.
The number of rules is equal to the number of types of entries to the power
of the number of conditions. In the above example, two types of entries are
possible (Y and N) and three types of conditions have been identified. The
number of rules equals 23 (2 x 2 x 2), which is equal to 8.
 Rule header The rule header identifies a rule numerically.

Table 32 labels the elements of the decision table in Table 31.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 98 of 170
Table 32 - Labelled decision table example
TITLE LEARNER PROGRESSION TABLE
TABLE SIZE 3C, 5A, 8R

Table size indicator

6.2 Constructing decision tables

This activity explains how to construct a decision table in seven steps.

Step 1
Gather all information on the problem to be solved by the table.

Step 2
Identify the conditions and actions to be included in the table. The following is
an example of a narrative with the conditions and actions indicated inside the
parentheses.

A man has decided to purchase a radio. The three factors that will influence his
selection of a radio are (C1) whether he can get an acceptable discount, (C2)
whether he can trade in his old radio, and (C3) whether the new radio comes
with a two-year guarantee.

If he can get a discount and trade in his old radio, he is prepared to forego the
guarantee and will (A1) buy the radio and pay cash. If he can get the discount
and a two-year guarantee but no trade allowance, or if he is given the
guarantee but he gets no discount and does not get a trade allowance and a
guarantee, he will (A2) buy the radio and take out a loan to pay for it. In all
other cases, he will (A3) not buy the radio.

Beware of including too many conditions. Remember that if you have a


condition for a female, it would be redundant if you also included a condition

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 99 of 170
for a male, because if a person is not female that person can only be male. By
the same token, it would be redundant to include a condition for a bank
balance over R8 000 as well as a condition for a bank balance of R8 000 or
less, because if there is an N indicated for the bank balance over R8 000, the
bank balance must be R8 000 or less. You will be heavily penalised if you
include two conditions instead of one with Y/N.

Step 3
In the third step, the condition stubs and action stubs can be listed.

C1 Discount?
C2 Trade?
C3 Guarantee?

A1 Buy – Pay cash


A2 Buy – Get loan
A3 Don't buy

Step 4
Determine the number of rules to be included in your table. The number of
rules equals 2 to the power of the number of conditions. A table with three
conditions will have eight rules (23), whereas one with four conditions will have
16 rules (24).

Table 33 - Conditions, actions, and rules


1 2 3 4 5 6 7 8
C1 Discount?
C2 Trade?
C3 Guarantee?

A1 Buy – Pay cash


A2 Buy – Get loan
A3 Do not buy

Step 5
Fill in the condition entries. For the first condition, the Y (yes) and N (no)
alternate once. For the second condition, they alternate twice and for the third
condition they alternate four times.

This formula ensures that you have included all possible combinations of
entries. In cases where some of the rules are impossible, you must identify
impossible rules by labelling them and crossing them out.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 100 of 170
Table 34 - Conditions entries
1 2 3 4 5 6 7 8
C1 Discount? Y Y Y Y N N N N
C2 Trade? Y Y N N Y Y N N
C3 Guarantee? Y N Y N Y N Y N

A1 Buy – Pay cash


A2 Buy – Get loan
A3 Do not buy

Rules are considered to be impossible when there is a specific restriction


prohibiting the combination of the conditions. When a combination of the
conditions does not make sense, it is also considered as impossible.

For example, if your table included conditions for a salary greater than R5 000
and a salary greater than R3 000, you would indicate as impossible the rule
that states N for salary greater than R3 000 and Y for salary greater than R5
000, as it is logically impossible for the same individual to earn less than R3
000 and more than R5 000 at the same time.

Step 6
Action entries must be filled in.

Table 35 - Conditions entries


1 2 3 4 5 6 7 8
C1 Discount? Y Y Y Y N N N N
C2 Trade? Y Y N N Y Y N N
C3 Guarantee? Y N Y N Y N Y N

A1 Buy – Pay cash X X


A2 Buy – Get loan X X X
A3 Do not buy X X X

Step 7
A title and table size indicator must be added. For the above example, the title
might be Radio Purchase Table and the table size 3C, 3A, 8R (three
conditions, three actions, and eight rules).

6.3 Summary

The steps in constructing a decision table are:

10. Gather the information.


11. Identify the conditions and actions.
12. List the conditions and actions.
13. Determine the number of rules to be included.
14. Fill in the condition entries and 'impossibles'.
15. Fill in the action entries.
16. Add a title and a table size indicator.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 101 of 170
6.4 Determining 'Impossibles' on a decision table

Impossible rules occur either when the specifications call for a restriction or
when the combination of the conditions is not possible. Consider the following
example:

Table 36 - Example to indicate 'impossibles'


TITLE Tax table
TABLE SIZE 2C, 3A, 4R, 1I

I
1 2 3 4
C1 Salary > Y Y N N
R10 000
C2 Salary > Y N Y N
R3 000

A1 45% tax X
A2 25% tax X
A3 10% tax X

In Table 36, there are two conditions and three actions. If a person earns
under R3 000, 10% tax is payable. If a person earns R3 000 or more, 25% tax
is payable. If a person earns over R10 000, 45% tax is payable. Rule 2 is
logically impossible as a person cannot simultaneously earn an amount that is
greater than R10 000 and less than R3 000.

6.5 Decision table practical examples

Using above steps as a guideline read the following narratives and construct a
decision table for each. The correct answers are shown below the question. If
you do not understand the examples, ask your lecturer for assistance.

6.5.1 Example one


If you buy a male dog, you receive a free collar. If you buy a female dog, you
receive a free bowl. If you buy a Dalmatian, you receive a free leash. If you
buy a Maltese Poodle, you receive a free blanket.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 102 of 170
Table 37 - Solution for 6.5.1
TITLE Dog types
TABLE SIZE 3C, 4A, 8R, 2I

I I
1 2 3 4 5 6 7 8
C1 Male dog Y Y Y Y N N N N
C2 Dalmatian Y Y N N Y Y N N
C3 Maltese poodle Y N Y N Y N Y N

A1 Free collar X X X
A2 Free bowl X X X
A3 Free leash X X
A4 Free blanket X X

Please note the following:


 There is no condition for a female dog because the dog is obviously female
where the condition entry is N for male dog.
 As there are 3 conditions, there are 8 rules (23).
 Rules 1 and 5 have been marked as impossible because it is not possible for
a dog to be 100% Dalmatian and 100% Maltese poodle at the same time.

6.5.2 Example two


Executives who earn above R8 000 are allowed to travel first class. Executives
who earn R8 000 or less are allowed to travel business class. Anyone else must
travel economy class.

Table 38 - Solution for 3.5.2


TITLE Flight table
TABLE SIZE 2C, 3A, 4R

1 2 3 4
C1 Executive Y Y N N
C2 Salary > Y N Y N
R8 000

A1 First Class X
A2 Business Class X
A3 Economy Class X X

Please note the following:


 There are 2 conditions. Where there is an N indicated for Executive, it is
obviously anyone else. Where there is an N for salary above R8 000, the
salary must be R8 000 or below.
 As there are 2 conditions, there are 4 rules (22).
 Note that the conditions are listed separately as it is important not to
combine two conditions.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 103 of 170
6.5.3 Example three
If you feel sick on a Monday, go to the doctor to get a doctor's note. If you feel
sick on a Friday, also go to the doctor for a doctor's note. If you feel sick any
other day, stay at home. If you feel sick on a Monday and/or Friday, and any
other day, go to the doctor to be booked off. If you feel good, go to work.

Table 39 – Solution for 6.5.3


TITLE SICK LEAVE
TABLE SIZE 3C, 4A, 8R

1 2 3 4 5 6 7 8
C1 Sick on Y Y Y Y N N N N
Monday
C2 Sick on Friday Y Y N N Y Y N N
C3 Sick other day Y N Y N Y N Y N

A1 Stay home X
A2 Doctor's note X X X
A3 Booked off X X X
A4 Go to work X

Please note the following:


 As there are 3 conditions, there are 8 rules (23).
 Note that the conditions are listed separately as it is important not to
combine two conditions.

Complete the decision table exercises and take each one to your lecturer to be
marked.

6.6 Key terms

 Decision table
 Title
 Table size
 Conditions
 Actions
 Rules
 Impossibles

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 104 of 170
6.7 Exercises

Draw a decision table to illustrate each of the following:

1. A woman goes to buy clothes, her options are:


 A red dress
 A cap
 A shirt
 A miniskirt

She cannot buy a shirt unless she buys a miniskirt as well. If she buys zero,
one, or two items of clothing she gets one pair of shoes. If she buys three
or four items of clothing she gets two pairs of shoes. In addition, the lady is
not allowed to buy a miniskirt unless she buys a cap.

2. Peter Jones wishes to purchase a boat. There are various options available:
 with life jackets
 with extra skis
 150HP engine instead of 100HP engine
 with trailer

The only restriction is that Peter cannot choose the 150HP engine unless he
takes a trailer as well. He may buy the boat at the regular price if he
chooses zero, one, or two of the options. If he chooses three or four
options, he will receive a discount.

3. A movie reviewer wants to set up a table to help in rating movies. The table
is based on four conditions: good acting, good plot, good costumes, and good
photography. A movie can be rated from one to four stars, four being the best.
 If the movie is good in all four areas, it is given four stars.
 If the movie has good acting and a good plot, it is given three stars.
 If the movie has good acting or a good plot, it is given two stars.
 If the movie has neither good acting nor a good plot, it is given one
star.

4. At a health spa, the following rules apply to the guests:


 If you weigh less than 60 kg and do not drink, you choose your meals
from the first menu.
 If you weigh between 60 kg and 69 kg, inclusive, and do not drink, you
choose your meals from the second menu.
 If you weigh 70 kg or more you choose your meals from the third
menu.
 If you drink, you can only choose your meals from the third menu.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 105 of 170
5. A building society offers benefits depending on age and amount invested.
 Age over 60 and balance over R2 000 - interest rate 18%.
 Age over 60 and balance R2 000 or less - interest rate 15%.
 Anyone else with a balance over R5 000 - interest rate 18%.
 Anyone else with a balance R5 000 or less - interest rate 15%.
 Anyone else with a balance R2 000 or less - interest rate 5%.

6.8 Revision questions

1. James decides to go for a swim in the river. Before he does, he checks the
water temperature and the speed at which the river is flowing.
 If the water speed is greater than 3 km/hr, he wears flippers.
 If the water temperature is below 10° C, he rubs Vaseline on himself to
keep warm.
 When the water speed is above 10 km/hr, he wears a cap.
 Otherwise, he swims normally without flippers, cap or Vaseline.

2. A bank wants to set up some simple rules for hiring people as bank tellers.
All people who apply for a job as a bank teller are given a maths aptitude
test.
 If a person has previous experience as a bank teller and either a high
school diploma or a test score greater than 80, the person will be hired
as a teller.
 If the person has a high school diploma and a test score greater than
80, or if they have previous experience as a teller, the person will be
hired as a trainee.
 In all other cases, they will not be hired.

Using the decision table created, determine whether or not Peter, who
achieved a test score of 86, has had previous experience as a computer
programmer, and has a high school diploma, will be hired and, if so,
whether he will be hired as a trainee or as a teller. Write down your
answer.

3. Maureen plans her vacation. Money, time and access to a car will determine
what she does.
 She may have four weeks vacation, or two weeks vacation, or no
vacation at all. She may choose only one of the three options.
 If she has enough money to go overseas and can take four weeks
vacation, she will go to Paris and London.
 If she has four weeks vacation and not enough money to go overseas,
but she has access to a car, she will go to Cape Town.
 If she has two weeks vacation and enough money to go overseas, she
will go to London.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 106 of 170
 If she has two weeks vacation and not enough money to go overseas,
she will spend time at home.
 Otherwise, she will not take a vacation.

4. The personnel department of a company wants to set up a table to


determine how many weeks of vacation each employee receives.
 Non-executive employees start with one week of vacation and earn one
more week of vacation at the end of every five-year period worked for
the company.
 Executive-level employees are given one extra week of vacation.
 The maximum period of leave a non-executive employee can have is
three weeks, whereas executives can have a maximum of four weeks.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 107 of 170
Unit 7 - System Flowcharts

At the end of this unit you will be able to:

 Understand the concept and function of system flowcharts.


 Recognise commonly used system flowchart symbols.
 Read and follow the logic of system flowcharts.
 Construct your own system flowcharts.

7.1 Introduction

A flowchart is a diagram that shows the series of steps taken in accomplishing


a task. It consists of symbols connected by data flow lines. The symbols
represent the steps in the process, whereas the lines connect the symbols and
establish a sequence for the steps. This section will deal with system
flowcharts.

A system flowchart is prepared by a systems analyst and shows the flow of


control through an information system, specifying all programs, inputs,
outputs, and files and databases used.

A system flowchart illustrates how computer programs fit together in an


information system. Each program on a system flowchart is referenced by a
name such as Program 1. The steps in the computer programs and the logic
required for each is not shown on the system flowchart. These appear on the
program flowchart. (See Unit 8 -Program Flowcharts).

A system flowchart is a convenient way to design the logic for systems. It is


less costly to determine, arrange and rearrange complex logic on a flowchart
than to correct logic errors in an implemented system. The flowchart becomes
an integral part of the system documentation. A system flowchart is vital if the
system is to be maintained easily and efficiently or if modifications are
necessary.

7.2 System flowchart symbols

The information technology industry has developed an international set of


standardised system flowchart symbols and symbol definitions. These allow
system flowcharts to be intelligible to anyone working in the industry anywhere
in the world. The following pages contain examples of the most common
system flowchart symbols and their function. System flowchart symbols are
drawn with a flowchart stencil, which should have been supplied with this
guide.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 108 of 170
Table 40 - System flowchart symbols
Symbol Example and function

Terminator

Represents the beginning or end of a flowchart.

Magnetic tape

Represents I/O function involving magnetic tape.

Disk storage

Represents I/O functions using storage such as a


disk.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 109 of 170
Processing

Represents the processing function or execution of


an operation. This typically appears when a step or
action is taken.

Flowline

This indicates the flow of information. Tape 1 is


used as input to Program 1.

Document

Represents reports, invoices, or any paper


documents that may be input/output in the
information system.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 110 of 170
Punched card

This represents all varieties of punched data cards.

Manual operation

This is a manual process that does not involve the


computer itself.

External storage

Represents the external storage of information (i.e.


storage not connected to the computer).

Manual input

Represents data entered manually at the keyboard


during processing.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 111 of 170
Sort

Represents the sorting process. A sort program can


be used instead of this symbol.

Merge

Represents the combination (merging) of two or


more sets into one.

Connector

This represents a junction point in the flow. Note


the page number convention when used as an off-
page connector. Use to avoid crossed lines and
cluttered flowcharts.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 112 of 170
7.3 System flowchart tips

 The flow of information will be as follows:

 The systems analyst will ask the programmer to write the program for the
contents of the process symbol.
 Files can be represented on disk or magnetic tape.
 No tape-to-tape, disk-to-disk, disk-to-tape, or disk/tape-to-document is
allowed. There must always be a process between storage media.
 A document is the product of a process. It cannot be produced directly from
a storage medium.
 Anything input at the keyboard, using the manual input symbol, is entered
into a program.
 A double-sided arrow is used to show that a disk is updated. When a tape is
updated, the old tape and the new tape must be shown.
 When sorting the contents of a file, it is permissible to use the SORT symbol
or a SORT program. The same is true for the MERGE symbol.
 When making a backup or copy of a file on disk, input the file into a backup
or copy program and output a new file on disk (called Backup file or Copy
file).
 The PROCESSING symbol is the most important, as without it the flow of
the diagram will be missing and will not make any sense. All actions or
steps take place here. If the processing symbol is left out any decisions
made will not be followed by an action. This is incorrect.

7.4 Reading a system flowchart

A systems analyst reviews system flowcharts for existing systems before


implementing and developing new systems. The following activity provides
practice in reading a flowchart.

7.4.1 Activity Instructions

The following questions are based on the system flowchart in Figure 7.1.
Answer the questions in the space provided and check your answers with a
lecturer.

The flow for the system flowchart in Figure 7.1 begins at the top with the
source document symbol. It shows that the Standard 10 marks are
keypunched onto cards that are input to Program 1, which is a sort program.
Answer the questions that follow.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 113 of 170
Figure 7.1 – System flowchart for exercise 1

a. On what medium are the Standard 10 marks first recorded?


b. What symbol could be used instead of the sort program?
c. Program 1 produces a transactions file. On what medium is this stored?
d. What does Program 2 (the print program) read?
e. What does Program 2 produce?
f. Name the two files that are read by Program 3 (the update program).
g. List the two output mediums indicated from Program 3.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 114 of 170
7.4.2 Activity Instructions
The following questions refer to the System flowchart in Figure 7.2.
Answer the questions that follow and check your answers with a
lecturer.

Figure 7.2 – System flowchart for exercise 2

a. The first symbol in the flowchart is a document symbol. To what kind of


document does this symbol refer?
b. The document is keypunched and verified. What kind of symbol is used
to represent this process? Is it an internal or external process?
c. The keypunching results in a card deck. What is the name given to this
deck?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 115 of 170
d. Program 1 sorts the transactions by ID number. On what medium is the
output of the sort operation recorded and what is the name assigned to
the file?
e. How many files are used as input to Program 2? What are their names?
f. The NEW MASTER TAPE is output from Program 2. What type of storage
medium contains this file?
g. The flowchart shows that a copy of the NEW MASTER TAPE is stored
externally. Why is a copy stored?
h. How many documents does Program 3 produce and what are their
names?

7.5 Key terms

 System flowchart
 Processing
 Flow line
 External storage
 Manual input
 Sort
 Merge

7.6 Exercises

These exercises give you practice in constructing system flowcharts.


You will be given guided practice in the following exercises. In the next
exercise, you will construct a flowchart on your own.

1. Construct a system flowchart showing the design of a payroll system that


prepares payroll reports. Complete the steps in the order in which they appear.

Draw a START symbol and a document symbol underneath it labelled TIME


SHEETS. The time sheets are source documents that serve as input to the
system.
Underneath the document symbol, draw a manual operation symbol and label
it KEYPUNCH. This indicates that the time sheets are keypunched.
Beneath the manual operation symbol, draw a punched card symbol and label
it TIMECARDS. This illustrates that the time data is keypunched onto cards.

2. Continue with the system flowchart which was drawn in the previous
question.

The time cards serve as input to Program 1 which sorts the data and produces
a sorted time card data tape file. Draw a process symbol with the label
PROGRAM 1 SORT BY EMPLOYEE NUMBER.
Below the process symbol, draw a tape symbol and label it SORTED TIME
CARD TAPE.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 116 of 170
The SORTED TIME CARD TAPE serves as input to the next processing step,
which validates each employee's time data and produces two output files.
Draw a process symbol with the label PROGRAM 2 VALIDATE TRANSACTIONS
below the tape symbol. Below the process symbol, draw a tape symbol labelled
VALIDATED TIME CARD FILE. To the right of the process symbol, draw a tape
symbol labelled FILE and an external storage symbol from this.

3. Continue with the system flowchart which was drawn in the previous
question.

The master payroll tape is updated using the old master and validated time
card tapes as input. Draw a process symbol labelled PROGRAM 3 UPDATE
MASTER.
Draw an arrow from the process symbol pointing to a tape symbol labelled
NEW EMPLOYEE MASTER.
Draw a tape symbol with an arrow pointing to the above process symbol. Label
the tape OLD EMPLOYEE MASTER.
Show that the NEW EMPLOYEE MASTER will become the OLD EMPLOYEE
MASTER on the next run by drawing a dashed flow line between the two tape
symbols.
Draw a flow line from PROGRAM 3 to a tape symbol and label it REPORT TAPE.
The REPORT TAPE is used as input to PROGRAM 4 REPORT WRITER.
PROGRAM 4 prints a report labelled REPORT.

4. On a separate piece of paper, construct a system flowchart for the following


system. If your answer is incorrect, ask your lecturer to explain your mistakes
to you.

The system begins with source documents called INVOICES, which are
keypunched onto cards, resulting in an INVOICE DECK.
The INVOICE DECK is manually checked and any incorrect cards are
keypunched again and rechecked.
Once the cards in the INVOICE DECK are all correct, the INVOICE DECK is
sorted and placed on a magnetic disk called SORTED INVOICE FILE.
The SORTED INVOICE FILE is used as input to three programs. PROGRAM 1
produces a report called REPORT 1.
PROGRAM 2 produces a magnetic tape called TABLE TAPE, which is used to
produce REPORT 2.
PROGRAM 3 uses a magnetic tape OLD MASTER as additional input.
PROGRAM 3 produces a magnetic tape called NEW MASTER.
NEW MASTER is input to PROGRAM 4. The date is entered at the keyboard and
REPORT 3 is produced.

5. A monthly tape file TAPE 1 is sorted onto disk for input to PROG 1. PROG 1
reads the monthly file and uses it to update DISK 2. DISK 2 is then read by
PROG 2, which updates DISK 3. TAPE 2 is then also created. TAPE 2 will be
used as input to the 'System' the next month.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 117 of 170
6. Three files (on disk) are sorted onto one disk file for input to PROG 1. PROG
1 also reads in a TRANSACTION file (tape). PROG 1 uses these 2 files to create
a DEBTORS file (disk) and a CREDITORS file (disk). A JOURNAL, showing
balances, is also printed. PROG 2 then uses both the DEBTORS and
CREDITORS files as input. Only records with a balance of zero will be written to
tape for storage.

7.7 Revision questions

1. The results of the learners at CTI are keypunched onto cards. The cards
form the TRANSACTION deck. A SORT program which sorts the transactions
according to learner number reads this TRANSACTION deck and outputs the
sorted data onto magnetic tape, called the TRANSACTIONS file. A copy of this
file is stored away. A program called PRINT reads these transactions and
produces a report. The same TRANSACTIONS file is read into the UPDATE
program, which also reads LAST YEAR's file, which is on tape. Update creates a
new LEARNER file on disk and this file is printed.

2. Five stores send daily transaction tapes to H.Q. once a day. PROG 1
validates each file's data, and if found incorrect, the incorrect tape/s are
manually corrected and the corrected tape/s are then processed again. When
all the files are correct, they are merged into one tape file for input to PROG 2.
PROG 2 will then update the MASTER STOCK file (on tape) and BOOKKEEPING
file (on tape) after copies of each of these two files are made. These copies are
then stored. PROG 2 also produces an UPDATE ANALYSIS report. The updated
BOOKKEEPING file will be used by PROG 3 to produce credit cheques.

3. Source documents are keypunched onto cards, which are read by PROG 1
and written onto 3 separate disk files – DISK 1, 2 and 3. DISK 2 is used as
input to PROG 2, which prints reports. DISK 3 is sorted onto a disk (DISK 4)
and this is read by PROG 3 which also updates the MASTER file (on tape). DISK
1 is sorted onto tape by PROG 4. This tape and the NEW MASTER are merged
to form a new file on disk, which is stored.

4. Source documents from two departments in Edgars are keypunched onto


cards. The cards are manually checked and if found to be incorrect are
punched again and rechecked. Once all the time cards are correct, they are
sorted by account number and transferred to disk (DISK 1). The source
documents are filed. Using DISK 1, program UPDATE updates the MASTER file
(on disk). Invoices are printed using information from the MASTER file. The
invoice date is entered via a keyboard.

5. A scrap dealer receives a car that he will use to sell second hand car parts.
The details of this car are punched onto cards that are then used to update the
CAR PARTS file on disk. A customer walks in and requests a part. This request
is entered manually via the keyboard into the PARTS program. This program

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 118 of 170
checks the CAR PARTS file to check availability. If a part is available, the part
is issued and the CAR PARTS and DAILY TRANSACTIONS files (both on disk)
are updated. The PARTS program then prints a sales advice slip that is given to
the customer. At the end of the day, the CONSOLIDATE program updates the
ISSUES disk file from the DAILY TRANSACTIONS file.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 119 of 170
Unit 8 - Program Flowcharts

At the end of this unit you will be able to:

 Understand the concept and function of program flowcharts.


 Recognise commonly used program flowchart symbols.
 Understand the necessity for designing the logic for computer programs.
 Construct your own program flowcharts using loops, logical decisions and
error messages.

8.1 Program flowchart

After a problem has been analysed, the program to be used in solving the
problem must be designed. The result of this design process is a program
flowchart. The program flowchart illustrates the logic of the program and gives
details on manipulating the data. It is less costly to determine, arrange and
rearrange complex logic on a flowchart than to correct logic errors in an
implemented program. A program flowchart is vital if the program is to be
maintained easily and efficiently or if modifications are necessary.

8.2 Program flowchart symbols

Program flowcharts are constructed with a set of standardised symbols that


make it easier for persons other than the original programmer to read and
maintain the program. The following pages contain examples of the most
widely used program flowchart symbols.

Table 41 - Program flowchart symbols


Symbol Example and function

Terminator

Indicates the beginning or end interruption of a program.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 120 of 170
Input/Output

Represents any function of an input/output device.

Process

Represents the program instructions that process data.

Decision

Indicates a point where branching based on a decision


occurs.

Connector

Represents a connection in the flow. Used when the steps


to be joined are located on the same page.

Off-page
connector

Used instead of the connector symbol when the flow is


continued on another page.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 121 of 170
8.3 Variables

Data manipulated by a computer program is represented by variables. A


variable is really a name that represents a number, character, or word. There
are several guidelines that should be followed when choosing a name for a
variable.

A variable name should be short, simple, descriptive, and meaningful and the
same name should be used throughout the program.

A variable name should begin with a letter and should preferably not be longer
than eight characters with no blanks.

Some computer languages are case-sensitive and so the variable name should
be in the same case throughout the program.

Do not use an underscore to join two words. The first letter of the second word
may be capitalised. For example, total units could be represented as totUnits.

Variable names should begin with a small letter. When joining two words, the
first letter of the second word should be capitalised. For example, totStud
could be used to represent total learners. This standard is to be used when
drawing program flowcharts.

8.4 Calculations

For calculations in program flowcharts:

 An asterisk (*) is used to indicate multiplication. For example:

grossPay = rate * hours

 A forward slash (/) is used to indicate division. For example:

classAverage = totalMarks/totLearners

 Percentages must be converted to decimal before you can work with them.
For example, if the tax is 10% of the gross salary the calculation would be
worked out as follows:

tax = grossPay * 0.1

8.5 Simple flowcharts

Draw a flowchart for a program that will do the following:

Input the number of kilometres on a car odometer when the car is filled with
petrol; input the number of kilometres on the odometer when the car was
previously filled, and the number of litres of petrol used to fill the car's tank.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 122 of 170
 Calculate the kilometres per litre by subtracting the previous odometer
reading from the current odometer reading and then dividing by the number
of litres used to fill the car.
 Print the kilometres per litre.

Use the following variable names:

Current kilometres = cKms


Previous kilometres = pKms
Kilometres per litre = kpl
Litres = ltrs

Figure 8.1 - Program flowchart example

NOTE The broken-line arrows are not part of the program flow; it is simply
used to add information to the diagram. A program flowchart must
contain a Start symbol, a Stop symbol, and at least one Input
symbol, one Output symbol, and one Process symbol.

8.6 Flowchart loops

Flowchart loops are used when a process may be performed one or more
times. Used, for example, when more than one record from a file is to be
processed by the computer program. In this case, the computer will read in the
next record after processing the current record. However, the program must
be able to stop when all the records have been processed. To make this
possible, an end-of-file (EOF) check is used. Every computer input device uses
a special record called an end-of-file, or EOF record.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 123 of 170
This EOF record is the last record in a file and when read by a program, can be
recognised. When using loops in your programs, an EOF check should be used,
unless specific instructions are given, such as, process until the number zero is
input. Use a decision symbol to represent an EOF check.

Figure 8.2 - EOF Check

8.6.1 Flowchart loop example


Study the following example of a program that performs a loop.

Figure 8.3 - Flowchart loop example

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 124 of 170
NOTE The broken-line arrows are not part of the program flow; it is simply
used to add information to the diagram. Records consisting of a
number of data fields are either read from a file or they may be input
by the user via the keyboard. Read is used to indicate the input that is
from a file, whereas Input is used to indicate that the input is manual
via the keyboard. It is important that the correct input term is used.

 The above program reads a record from a file containing the following
fields: name, rate, hours, and deductions.

 An EOF check determines whether the record is the last record on the file. If
the EOF condition is true, the program stops. Otherwise, the program will
continue to process the records.

 The gross pay is calculated by multiplying the hours by the rate. The net
pay is calculated by subtracting the deductions from the gross pay. A pay-
slip is then printed and the next record on the file is read and processed.

8.6.2 for loops


When processing a loop a specific number of times, a for loop is used. This
may be shown in one of two ways when drawing a program flowchart, either
using the for loop symbol or using decision and increment symbols as shown
previously. Below is an example of a for loop symbol:

This symbol means the for loop will be processed five times – that is, for count
= 0 to count = 4, increment count by 1 where:

count – variable used as a counter in the for loop.


0 – the starting value for the for loop.
4 – the end value.
1 – the amount of incrementation each time the for statement loops.

For example, draw a program flowchart to show the following:

Input 5 numbers from the keyboard and determine, then print, the total value
of the numbers input.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 125 of 170
Figure 8.4 – Example of a for loop using the for symbol

Alternatively, using decision and increment symbols:

Figure 8.5 – Alternative method of showing a for loop

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 126 of 170
8.7 Logical decisions

When supplying the information to be included in a program, it is vital to


remember two important facts about computers:

1. Computers can determine and act on only 'Yes' and 'No' decisions.
2. You must supply every decision the computer is to make and every
resulting action for each decision.

These factors require the programmer to pay a great deal of attention to the
logic of the program.

8.7.1 Determining logical decisions


The first step in determining the logical decisions to be made in a program is to
identify the factors upon which the decisions are to be based. You must then
determine the actions to be taken as a result of the decisions.

8.7.2 Illustrating logical decisions


The following special symbols are frequently used in flowcharts to indicate
relationships:

> Greater than

< Less than

> Greater than or equal to

< Less than or equal to

= Equal

<> Not equal

8.8 Accumulating and incrementing totals

When many records from a file are processed, it is often necessary to


accumulate or increment grand totals, which relate to all of the records. There
are three rules to remember when accumulating or incrementing totals:

The totals to be accumulated or incremented must be initialised to zero at


the beginning of the program before the main processing loop because this
clears the memory.
17. Totals that have been initialised must be accumulated or incremented
within the main processing loop.
18. Totals that have been accumulated or incremented must be printed at the
end of the program after the end-of-file condition has been met.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 127 of 170
8.8.1 Accumulating totals – example 1
Records for employees at an advertising agency are read from a file. Each
record contains the employee name, gross pay and tax. Draw a program
flowchart that will print a payslip for each of the employees. The output values
will be the name, gross pay, tax and net pay. The Director wants to know the
total amount that was paid out to all of the employees. Net pay is the total
that will be accumulated in this example. The variable names used are:

Gross pay = gPay


Net pay = nPay
Tax = tax
Total Net Pay = totNetPay

Figure 8.6 - Accumulation example 1

Using the above example, suppose the first record contained the following
data:

name : John Smith


gPay : 2 000
tax : 200

The net pay is equal to the gross pay minus tax, which would give us R1 800.
totNetPay has been initialised to zero and will become 1 800 with John Smith's

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 128 of 170
net pay added to it. If the net pay for the next record is 1 200, totNetPay will
become 3 000.

The program will continue adding the net pay for each record to totNetPay.
After all of the records have been processed, totNetPay will be printed.

8.8.2 Incrementing totals – example 2


There are three candidates for SRC president. Votes have been entered into a
file and each record contains a number, which represents a vote for one of the
three candidates.

Draw a program flowchart that will calculate the total votes for each of the
three candidates. A total of all the votes must be printed at the end of file.
Variable names:

Total votes for candidate 1 = tc1


Total votes for candidate 2 = tc2
Total votes for candidate 3 = tc3
Total votes overall = total
Number = num

Refer to the Program Flowchart in Figure 8.7 for a suggested solution.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 129 of 170
Figure 8.7 – Example 2

NOTE The broken-line arrows are not part of the program flow; they are
used to add information to the diagram.

8.9 Printed output

When a program executes a loop, each record in a file is processed within the
main loop and final totals are printed at the end of the program. To print a
report, it is necessary to print the headings before entering the loop. Each line
of the report will be printed each time the loop executes and final totals will be
printed at the end.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 130 of 170
8.9.1 Printed output – example 1

NOTE The broken-line arrows are not part of the program flow; they are
used to add information to the diagram.

Figure 8.8 - Printed output example 1

The printed output for the flowchart in Figure 8.8 would look as follows:

Number Name Rate of pay Hours Gross pay

1 Fred Smith 10.00 40 400.00

2 Jane Blair 20.00 45 900.00

: : : : :

Figure 8.9 - Segment of printed output

8.9.2 Printed output – example 2


Sometimes it will be necessary to incorporate category details, a description,
or a message into your flowchart.

Study Figure 8.10 shown below:

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 131 of 170
Figure 8.10 - Printed output example 2

NOTE The broken-line arrows are not part of the program flow; they are
used to add information to the diagram.

8.10 Error checking

We previously learnt that computers can determine and act only on 'yes' and
'no' conditions, and that the programmer must supply every decision the
computer is to make and every resulting action for each decision. It is
extremely important that the program should be able to recover from incorrect
input from the user. This is done through the use of error messages. If error
checking is not used in a program, the program will crash when unexpected
information is input.

8.10.1 Error checking example


In Figure 8.11, the program will accept only three car types. If the car type is
0, the program will stop. If the car type is 1 or 2, an appropriate message will
be printed. If any other number is entered an error message will be printed
and the program will read the next car type.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 132 of 170
Figure 8.11 - Error message example

8.11 Key terms

 Program flowchart
 Terminator
 Input/Output
 Process
 Decision
 Flowchart loops
 Count
 Logical decisions

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 133 of 170
8.12 Exercises

Using Figure 8.12 as a guideline:

1. Construct a program flowchart for a computer program that will do the


following:
 Input an employee's name, hourly rate of pay and number of hours
worked.
 Calculate the following:
o Gross pay as hours worked times rate.
o PAYE as 25% of gross pay.
o UIF as 2% of gross pay.
o Net pay as gross pay minus PAYE minus UIF.
 Print out the employee's name, gross pay, PAYE, UIF, and net pay.

Use the following variable names.

Employee name = name


Hourly pay rate = rate
Hours worked = hours
PAYE = paye
UIF = uif
Net Pay = nPay
Gross Pay = gPay

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 134 of 170
Figure 8.12 - Program flowchart exercise 1

2. Draw a flowchart of a program that will do the following:


 Read a record from a file containing a stock item's description, this
month's stock, last month's stock, and the number of items received
during the month.
 Calculate how many items were used during the month by taking last
month's quantity on hand, adding to it the quantity received during the
month, and then subtracting the quantity on hand this month.
 Print the item's description and quantity used during the month.
 Read the next inventory item and repeat until all items have been read
in.

Use the following variable names.


Item description = desc
Last month's stock = lms
This month's stock = tms
Items received = rec
Items used = used

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 135 of 170
3. Construct a flowchart for a program that will do the following:
 Read an employee's name, rate of pay, and hours worked from an
employee file.
If the employee worked zero hours, read the next employee. If the employee
worked more than zero hours, calculate gross pay as rate times hours and
print out the employee's name and gross pay.
 Continue reading employee records until the computer encounters an
end-of-file check.

Use the following variable names.


Employee name = name
Rate of pay = rop
Hours worked = hours
Gross pay = gPay

4. Draw a program flowchart for the following problem. Use your own variable
names. To be accepted as a Flyaway airline employee, an applicant must be
over 21 but under 35 years of age, over 170 cm tall and weigh more than 60
kilograms. Otherwise, the applicant must be rejected. The required input
values are name, age, height and weight.

Processing continues until the name 'ZZZ' is entered.

The factors are:


Name = 'ZZZ'
Over 21 years of age
Under 35 years of age
Height over 170 cm
Weight over 60 kilograms.

The actions are:


 Print name of acceptable applicant.
 Reject applicant and read next record.
 Stop processing when the name 'ZZZ' is input.

As the name is used as an end-of-file condition, it is better and more efficient


programming practice to first input the name, test it, then only if the end-of-
file condition is NOT satisfied, input the rest of the data.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 136 of 170
8.13 Revision questions

1. Draw a program flowchart to convert the seconds it took runners to


complete a marathon into hours, minutes and seconds. Determine the total
number of female runners and the total number of male runners. Count
how many male runners completed the marathon in less than five hours
and how many male runners completed it in less than six hours. Print these
totals once all the runners have been processed. Processing continues until
the end of the file is reached.

Input: sex, seconds and name


Output: sex, name, hours, minutes and seconds

2. Draw a program flowchart for the following:

A car hire company produces a monthly analysis report.

Input: car type (1-5)


odometer reading before the car was taken
odometer reading after the car was returned
number of days the car was used

Output: car type, number of kilometres travelled, number of days


used and cost.
Conditions: The cost of the hiring per km differs from one car type to
the next:
Car 1: Executive = R20
Car 2: Under Executive = R15
Car 3: High Class = R12
Car 4: Medium Class = R10
Car 5: Low Class = R8

Car 1: Clients may use this car for a maximum of 5 days. If the
client exceeds this limit, a 10% surcharge is added to the
final cost.

Car 3: Because of the popularity of this class, the clients may use it
for a maximum period of 10 days. If the 10 day limit is
exceeded, the client is charged an extra R3 per kilometre.

Ensure that only car types 1 – 5 will be accepted as input.


At the end of the report, for car types 1 and 3, print out the total number
of kilometres travelled, the number of cars that were hired and the total
number of days the cars were used. Processing continues until the end of
the file is reached.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 137 of 170
3. Draw a program flowchart to produce a learner grading report.

The following input values are read from a file: learner number, learner
name, maximum test score and learner test score.

Processing: The percentage obtained by each learner must be calculated.


This percentage is to be matched against the corresponding class message:

0 – 44 Fail
45 – 49 Supplementary
50 – 59 3rd class
60 – 69 2nd class
70 – 74 Upper second class
75 – 100 First class

A list of all the learners is to be printed, showing each learner's number,


name, percentage and class message. Totals for each grading class must
be accumulated and printed after the end-of-file has been reached (i.e.
learner number = 0).

4. Draw a program flowchart to illustrate the logic required to produce a Gross


Profit Report.

Input: item number, description, sales amount and cost amount.


Output: item number, description, sales amount, cost amount and gross
profit.

The Gross Profit formula: Sales amount – cost amount. The sales amount,
cost amount and the gross profit fields are each totalled.

Continue processing until an end-of file indicator is reached. A sample


segment of the report is given below:

Item Description Sales Cost Profit


10001 Ammonia 30.90 20.00 10.90
10023 Matches 200.00 100.00 100.00
22560 Nutties 34.80 20.00 14.80
… … …
… … …
… … …
Final totals R1 000.00 R596.80 R403.20

5. Draw a program flowchart to represent the logic required to prepare a


Weekly Payroll Report.

Input: employee number, name, hours worked, rate of pay and deductions.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 138 of 170
Output: employee number, name, hours worked, rate of pay, regular
earnings, overtime earnings, deductions and net pay.

Regular pay (hours * rate of pay) is earned on 40 hours or less. Overtime pay
(1.5 * number of hours worked overtime * rate of pay) is earned on hours in
excess of 40.

Continue processing until an end-of-file indicator is reached.

Empl. Name Hrs Rate Reg Over Deduct Net


No. Pay Pay Pay

123 H. Smit 42 2.00 80.00 6.00 10.00 76.00

180 J. Dunn 30 2.50 75.00 0.00 7.00 68.00

198 P. Lin 45 3.50 140.00 26.25 20.00 146.25

Final 800.00 560.00 100.00 1260.00


totals

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 139 of 170
Unit 9 - Trace tables

At the end of this unit you will be able to:

 Check the logic of your program flowcharts using trace tables.

9.1 Introduction to trace tables

A trace table is a useful tool in the development of program flowcharts because


it is like running a program on paper. It forces the programmer to be
consistent and check the program line-by-line or box-by-box, without taking
shortcuts. A trace table serves the following functions:

It gives the programmer a deeper understanding of how a program works.


It allows the programmer to see the output before actually coding and
debugging on computer.
It serves as a teaching and learning tool for concepts like variables and values.
It allows for the detection of logic errors and helps identify ways of correcting
the problem.

9.2 A trace table construction

Constructing a trace table is as simple as drawing columns on a ruled page.


The first column is used for referencing the line number (for program code) or
box number (for flowcharts). Next are columns for variables – each variable
having its own column. These are followed by columns for control structures,
i.e. the conditions/decisions found in the various kinds of loops. The last
column is used for output or print statements. The order of the columns from
left to right is not important.

Test data is necessary to draw a trace table. Test values are placed in the
relevant block (column-row intersection). These values are updated
accordingly as we step through the program. Test data must be planned and it
must include extreme values (upper and lower) and special values to test all
parts of the program. While it is not possible to test all values to show the
robustness of a program, all that is required to prove failure, is one test case in
which the program does not work.

NOTE MODULO (the MOD operator) - 'A mod B' gives the answer 'the
whole number remainder when A is divided by B'. For example, 16
mod 3 will give an answer of 1, i.e. 16/3 = 5 remainder 1.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 140 of 170
9.3 Trace table example

Study the flowchart in Figure 9.1 below:

Figure 9.1 - Flowchart for trace table example

Let us assume that the following values are input at box 2:

A B
8 6
15 3
20 8
12 4
7 2

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 141 of 170
Table 42 - Trace table
Box N K A B A mod B = N = 5? Output
No. 0?
1 0 0
2 8 6
3 1
4 No
7 No
2 15 3
3 2
4 Yes
5 1
6 15 3
7 No
2 20 8
3 3
4 No
7 No
2 12 4
3 4
4 Yes
5 2
6 12 4
7 No
2 7 2
3 5
4 No
7 Yes
8 2

Please note the following concerning Table 42.

The first column contains the box number; the next four columns contain the
variable names, followed by the control structures and the output.
The trace table keeps track of the results for each input. You will notice that
the variables N and K are incremented depending on the results of the logical
decisions.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 142 of 170
9.4 Key terms

 Output
 Decision
 Count
 Trace table

9.5 Exercises

1. Study the example in Figure 9.2 and draw a trace table. The following
values have been input at box 2:
Num
9, 23, 7, 14, 11.
Take your trace table to your lecturer to be marked before you continue with
the rest of this exercise.

Figure 9.2 – Summing Program

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 143 of 170
2. Answer the following questions about Figure 9.3 and take them to your
lecturer to be marked.

a. Construct a trace table in order to answer this question. Give the output
with the following as input:

name address tmread lmread


John Westville 790 560
Mary Randburg 1200 600
Rockie Hometowns 700 300
End-of-file indicator

b. The flowchart has one logic error. Identify the box in which it occurs and
give the corrected box.
c. Can box number 6 and box number 7 be interchanged? Explain why?
d. Can box number 4 and box number 6 be interchanged? Explain why?
e. Which box(es) represent the body of the loop?
f. When will the loop stop?
g. What is an infinite loop? Which box when removed will create an infinite
loop?
h. Predict the output and effect if box 1 was placed after box 3.
i. What is meant by initialisation of a variable? Where in the flowchart does
this occur?
j. Alter and redraw the flowchart to incorporate the following:
 Any necessary corrections.
 Calculate and print the total number of households billed.
 Print a warning message for each household that is using more than 400
units.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 144 of 170
Figure 9.3 – Electricity Meter

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 145 of 170
3. Study the flowchart and answer the questions that follow:

a. Construct a trace table using the following data: Pete, John, Anna, ZZZ.
b. The flowchart has one error - identify the box in which it occurs.
c. How would you change the flowchart to correct the error?
d. Does initialisation of a variable occur? If so, in which box does it occur,
what is the name of the variable, and to what value is the variable
initialised?
e. In which box does input occur?
f. In which box does output occur?
g. Should you wish to print the names of all those programmers who do
not have the name 'ZZZ', would you insert the print symbol before or
after box 3?

4. Draw a flowchart that will:

a. Calculate pay for each employee in a company.


b. Print these details on a monthly report.

Each employee record in the employee file holds the employee number,
name, hours worked and the rate of pay. The output for each employee
includes the employee number, name, hours worked, rate of pay and the
gross pay.

Processing continues until an employee number of 0000 is read.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 146 of 170
The hours worked and the gross pay for each employee must be
accumulated and these totals printed after the end-of-file condition has
been met.

Construct a trace table for the above exercise using the following data as
input:

Employee Name Hours Rate of Pay


Number Worked
------------------------------------------------------------------
1. 034 J Smith 184 R20
2. 245 P Brown 200 R25
3. 546 J Louw 160 R20
4. 0000

9.6 Revision questions

1. Draw a program flowchart to illustrate the logic required to produce a


customer sales report.

Input: customer number, name, balance, code field.


Output: customer number, name, balance, discount percentage or service
charge, balance due and the code category (i.e. each customer is identified as
being 'Current', '30-60 days', or 'Over 60 days'.)

Balance due is calculated using one of the following three formulae:

Balance due = balance - (balance * discount percentage)


Balance due = balance + (balance * service charge)
Balance due = balance

The code field in the input record indicates whether the customer's balance is
current, 30 days old, or 60 days old.

Code categories:
Code 1: current account – 3% cash discount.
Code 2: 30 – 60 days overdue – no discount.
Code 3: Over 60 days overdue – 1.5% service charge.

Print an error message if a code other than 1, 2 or 3 is input. Processing


continues until an end-of-file indicator is reached.

Table 43 - Sample output


Cust No. Name Balance Discount Service Balance
Charge due
100 ACME 500.00 3% 485.00 Current

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 147 of 170
123 Ian & Co 200.00 200.00 30-60 days
255 Potts Ltd 200.00 1.5% 203.00 Over 60
days

Using the relevant data above as input, construct a trace table to show that
your program flowchart will produce the same output as shown in Table 9.2.
Include an incorrect code in your data to show that an error message is
output.

NOTE The steps in the program flowchart can be numbered in any order.
Where calculations are necessary (such as, determining the balance
due), complete these by using the values in the trace table and
check that the answer is the same as shown in Table 43.

2. You are required to draw a program flowchart to produce a Sales


Commission report.

Input: salesman number, name, sales amount and code.


Output: salesman number, name, sales amount, commission, code and
employee category type.

Code categories:

Code 1: a part-time employee – no commission is paid to employees in this


category.
Code 2: a full-time salaried employee – receives 5% commission on all sales.
Code 3: commission only employee – receives 5% commission on all sales of
R1 000 or less and 7% commission on all sales over R1 000.

E.g. A 'commission only' employee with sales of R1 200 receives a commission


of 5% on R1 000 (i.e. R50) and 7% on R200 (i.e. R14). Processing continues
until an end-of-file indicator is reached.

Salesman Name Sales Comm. Code Category


No. Amount Amount
115 Ann Smit 195.00 0.00 1 Part time
192 Sam Bean 5 000.00 250.00 2 Full time
237 John Pansy 1 200.00 64.00 3 Comm

Final totals 34 000.00 1 235.00

3. Draw a program flowchart to count how many male employees earn above
R1 000 and how many female employees earn below R5 000.

Input: employee number


sex (m or f)
salary

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 148 of 170
Output: number of males earning above R1 000.
number of females earning below R5 000.

Processing continues until an employee number of 0 is entered.

4. Draw a program flowchart for the following:

Input: department No. (1 or 2)


salesperson name
sales amount

If a salesperson sells more than R1 000 he/she gets 5% commission,


otherwise he/she gets 3% commission.

Print a report showing the department No., salesperson name, sales amount
and commission for each salesperson.
At the end of the report, print the total number of salespersons in each
department and the total sales amount for all salespeople. Processing
continues until an end-of-file indicator is reached. Construct a trace table for
the above example.

Use the following test data:

Dept No Name Sales Amount


2 John R950
3 Piet R2 000
1 Mary R1 500
EOF

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 149 of 170
Test Your Knowledge

Complete the following questions as additional practice for the written


questions section in the examination. Check your answers with your lecturer.

Truth tables
Show all the steps.

1. Prove the following using a truth table.

2. Prove the following using a truth table.

(X + Y) (X + Y') = X

3. Prove the following using a truth table.

4. Prove the following using a truth table.

PQ + (P'+ Q') P = P

5. Prove the following using a truth table.

(AB)' = A' + B'

6. Prove the following using a truth table.

(x + y)' = x'y'

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 150 of 170
Logic diagrams to and from expressions or equations

NOTE For questions 1 to 8, label each step and use only two inputs per logic
gate.

1. Draw the logic diagram for the expression.

{[(A + B)' + (A' + B')] [CD]}'

2. Draw the logic diagram for the expression.

{[(P + Q)' (S + T) R] U}

3. Draw the logic diagram for the expression.

{[(L' + M') (N + P)']'R + S'}

4. Draw the logic diagram for the expression.

A (B + C') (D + E'F)

5. Draw the logic diagram for the expression.

(A + B) (A'CD + E)

6. Draw the logic diagram for the expression.

(R + S) (R'LX + Q)'

7. Draw the logic diagram for the expression.

[D + E + F (G + H)] + J'

8. Draw the logic diagram for the expression.

(AB)(CD)(E'F)

9. Write down the output expression for the logic diagram.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 151 of 170
10. Write down the output expression for the logic diagram.

11. Write down the output expression for the logic diagram.

12. Write down the output expression for the logic diagram.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 152 of 170
Boolean algebra

NOTE Show all working. You do NOT need to state the law or theorem used.

1. Reduce the following equation to its lowest form.

F = AB'C + ABC + A'B'C' + A'BC'

2. Reduce the following equation to its lowest form.

F = x + (x' + y)

3. Reduce the following equation to its lowest form.

F = (DE) (GD') (G + G')

4. Reduce the following equation to its lowest form.

F = P'QRS + P'Q'RS + PQRS + PQ'RS

5. Reduce the following equation to its lowest form.

F = XYX'Z + XZ' + XZ + Y

6. Reduce the following equation to its lowest form.

F = JK + N + KLM + N'

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 153 of 170
De Morgan's theorem

NOTE Show all the steps. Vincula may be used instead of ' for all answers.
You do NOT have to provide the name of the law or theorem used.

1. Simplify the following equation using De Morgan's theorem and Boolean


algebra.

F = [(P + Q)'(R + S')'P'Q'R']'

2. Simplify the following equation using De Morgan's theorem and Boolean


algebra.

F = [(K + L)'M]' + H'

3. Simplify the following equation using De Morgan's theorem and Boolean


algebra.

F = X + X'Y

4. On the paper provided, simplify the following equation using De Morgan's


theorem and Boolean algebra.

F = WY + YZ + W' + Y'

5. Simplify the following equation using De Morgan's theorem and Boolean


algebra.

F = W + X + YZ + (WX)'

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 154 of 170
Karnaugh maps

NOTE Show all working. You may choose to show either the algebraic,
binary, or decimal terms in the mapping.

1. Simplify the following equation using a Karnaugh map. Derive your binary
and decimal minterms before plotting the map.

F = AB'C + ABC + A'B'C' + A'BC'

2. Simplify the following equation using a Karnaugh map. Derive your binary
and decimal minterms before plotting the map.

F = A'C + A'B + AB'C + BC

3. Simplify the following equation using a Karnaugh map. Derive your binary
and decimal minterms before plotting the map.

F = B'{D [A(C + C') + A'(C + C')]}

4. Simplify the following equation using a Karnaugh map. Derive your binary
and decimal minterms before plotting the map.

F = AB'CD' + ABC + AB'CD

5. Simplify the following equation using a Karnaugh map. Derive your binary
and decimal minterms before plotting the map.

F = J'K'L' + KL' + JK'L'

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 155 of 170
Decision tables

1. Mary decides to go to the beach. The weather could be sunny or rainy, hot
or cold, clear or cloudy.

a. If it is sunny she will wear a hat.


b. If it is sunny with clouds, she will wear sunglasses.
c. If it is hot and sunny, she will wear her swimming costume.
d. If it is rainy she will wear a raincoat.
e. If it is cold she will wear a jersey.

Draw a decision table to see what she will wear in all conditions and label
the impossibilities, if any.

2. A motor insurance company needs to determine the type of policy it should


recommend for a potential policy holder, depending on the driver's age,
driving record and the type of car he/she drives.

a. If the driver is over 21 years old and drives a car valued at over R100
000 then he/she should get a fully comprehensive policy.
b. If the driver has a good record, he/she should take out a third party,
fire and theft policy.
c. If the driver is 21 years old or younger and drives a car valued at over
R100 000, he/she should take out a third party only policy.
d. Anyone else should not be allowed to take out a policy.

Construct a decision table showing the conditions, rules and actions to


determine the correct policy to recommend. Indicate the 'impossible'
conditions, if any.

3. A credit company needs to determine the credit allowed for its customers,
depending on whether the customer is a company or an individual, where
the customer is based, and whether the customer has a good reference.

a. If the customer is a company based in South Africa with a good


reference, the customer gets R1 000 credit.
b. If the customer is not based in South Africa but is either a company or
has a good reference, the customer gets R800 credit.
c. Anyone else will get credit of R500 except if the customer is not based
in South Africa, in which case the customer will get no credit.

Construct a decision table showing the conditions, rules and actions to


determine the correct credit allowed. Indicate the 'impossible' conditions, if
any.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 156 of 170
4. An airline company calculates airfares depending on children's ages and
whether they sit on a parent's lap or not.

If a child is four years old or younger, he/she pays 25% of the normal
airfare, unless he/she sits on a parent's lap, in which case there is no
charge. Children older than four may not sit on a parent's lap to save on
airfares.

Children aged between four and sixteen years pay 55% of the normal
airfare. Children sixteen years and older are considered adults and pay the
full fare.

Construct a decision table showing the conditions, rules and actions to


determine the correct airfares. Indicate the 'impossible' conditions, if any.

5. At the end of every two months, lecturers at a college prepare and post a
report to each learner's sponsor. Depending on a learner's performance,
the lecturer may also need to telephone the sponsor to discuss the learner,
or to arrange a meeting to do so.

A meeting is arranged in the event of two or more of the following


happening:

a. If the learner's course average is less than 65%.


b. If the learner fails a course.
c. If the learner is more than five days behind schedule.

Should only one of the above happen, the lecturer only needs to speak to
the sponsor over the telephone.

Construct a decision table showing the conditions, rules and actions that
determine whether or not the sponsor must be contacted. Show the
impossibilities, if any.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 157 of 170
System flowcharts

1. Draw a system flowchart for the following.

At a retail store, source documents from the men's, ladies', and children's
departments are entered via a keyboard into a SALES file (on disk).

The SALES file is then sorted daily onto a disk file called SORTED SALES.
This is used to update the MASTER CUSTOMER file (on disk). A backup of
the MASTER CUSTOMER file is made on disk.

Once a month, the MASTER CUSTOMER file is used to print statements for
the clients. The date is entered via the keyboard.

A monthly report is also produced with the details of customers who have
bought goods during the month and this information is also put onto a tape
file, which is stored.

2. Draw a system flowchart for the following.

Source documents of customers' orders at a company which sells tools are


entered via a keyboard into records stored on a disk file called ORDERS.

This disk file is then read by a sort program, which sorts the orders into
alphabetical order by description.

This sorted file is then read by a program called INV that produces two files,
the INVOICE file and the STOCK TRANSACTION file (both on disk).

The STOCK TRANSACTION file is read by a program called UPDATE which


updates the MASTER STOCK file (on disk).

The INVOICE file together with a BAD DEBTORS file (on disk) is then read into
a program to check if any of the invoices belong to bad debtors. Two reports
are printed – one listing all the invoices belonging to the bad debtors and one
listing all debtors.

3. Draw a system flowchart for the following computer system.

Customer payments are received and stored in a payments received file


(PAYFILE) (on disk). A VALIDATE program checks whether the customer
numbers are valid. Valid records are written to a disk file called VALIDPAY
and invalid records are written to the ERRFILE disk file, which is printed out
to an Error Report.

The VALIDPAY file is sorted according to customer number onto a disk file
called VALIDFILE2. The VALIDFILE2 is then used to update the CUSTFILE
(on disk) that contains the amount owed by customers.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 158 of 170
Monthly statements are printed from this updated file for the customers
who still owe money.

4. Draw a system flowchart for the following computer system.

The Stock department receives documents for stock issued and received. A
keyboard is used to enter the data from these documents into a stock
transaction file (STOCKTRANS) (on disk).

This file is sorted by part number into a sorted transactions disk file
(STOCKTRANS2). This sorted file is read into a program, which creates two
files on disk – one for stock items received (STOCKIN) and one for stock
items issued (STOCKOUT).

The STOCKIN file is used together with the stock master file (STOCK) (on
disk) to create a NEWSTOCK file on disk.

The NEWSTOCK file is used to print a report.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 159 of 170
Program flowcharts

1. Draw a detailed program flowchart of the following.

Input: Consists of a file of magazine subscriber records. Each record


contains the following fields:
– Subscriber's name
– Subscriber's address
– Code.

The code field may contain one of the following values:

 To indicate an individual subscriber


 To indicate a corporate subscriber.

Include error checks in the event that an invalid code is input.

Process: Your program must count the subscribers in each category,


giving two totals in all.

Output: This is to consist of a name and address label for every subscriber
(to post the magazine to) and when the EOF is encountered, the
two totals mentioned above must be printed.

Processing ends after EOF is reached.

2. Draw a program flowchart for the following.

The police computer contains records of stolen cars, which have been
recovered. Each record has a field for the registration number and a flag
field. These details are used as input.

The flag field consists of a letter, which relates to a specific message:

 Flag A: 'Returned to owner'


 Flag B: 'Unclaimed'.

If the flag is an invalid letter (i.e. not an 'A', or 'B') an error message must
be printed.

The police commissioner wants a printout of the following:

a. The registration number of each unclaimed vehicle


b. At EOF, the total number of cars returned to their owners
c. At EOF, the total number of unclaimed vehicles.

Processing stops after EOF is reached.

3. Draw a program flowchart for the following program.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 160 of 170
A game of dice is played in which the player continues to throw the dice
until the number six is thrown. Count the number of times the player
throws a one. When the player throws a six, print a congratulatory
message, then print the number of ones thrown and exit the program.

4. Draw a program flowchart to calculate the average in the following


program.

The program must allow the user to input a series of numbers. When the
user enters a zero, the program must calculate and print the average value
of these numbers.

5. Draw a program flowchart for the following program.

Read learner records from a file. Each record contains the learner's name,
address and an examination mark out of 350.

Print the names and percentages with a remark for all the learners
according to the following criteria.

1. Less than 50% is a fail.


2. 80% or above is a distinction.
3. For any other percentage, the learner just gets a pass remark.

Stop processing when EOF is reached.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 161 of 170
Trace tables

1. Accumulate numbers:

Study the flowchart and answer the following five questions.

a. Construct a trace table using the following data: 6, 12, 4, 0.

b. The flowchart has one error - identify the box in which it occurs.

c. In which box does initialisation occur?

d. Which box would you change for the program to count how many numbers
there are before the number zero is entered, instead of accumulating the total
value of the numbers?

e. How would you change the box to reflect point d. above?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 162 of 170
2. Count numbers:

Study the flowchart and answer the following five questions.

a. Construct a trace table using the following data: 3, 9, 10, 0.

b. The flowchart has one error - identify the box in which it occurs.

c. In which box does a decision occur?

d. Which box would you change for the program to add the value of the
numbers instead of counting how many numbers there are before the number
0 is entered?

e. How would you change the box to reflect d. above?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 163 of 170
3. Largest number:

Study the flowchart and answer the following five questions.

a. Construct a trace table using the following data: 12, 13, 6, 0.

b. The flowchart has one logical error - identify the box in which it occurs.

c. How would you change the flowchart to correct the logic?

d. In which box does the final output occur?

e. Which box would you change if you wanted the last number input to be the
only final output?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 164 of 170
4. Smallest number:

Study the flowchart and answer the following five questions.

a. Construct a trace table using the following data: 2, 9, 7, 0.

b. The flowchart has one logical error - identify the box in which it occurs.

c. How would you change the flowchart to correct the logic?

d. In which box does the final output occur?

e. Which box would you change if you wanted to output the last number input
as well?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 165 of 170
5. Number of learners:

Study the flowchart and answer the following five questions.

a. Construct a trace table using the following data: John, Piet, Harry, ZZZ.

b. The flowchart has one error - identify the box in which it occurs.

c. How would you change the flowchart to correct the error?

d. In which box does output occur?

e. Should you wish to print the names of all those learners who do not have
the name 'ZZZ', would you insert the print symbol before or after box 3?

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 166 of 170
Examination Requirements

The examination is three hours long for a total of 160 marks. The breakdown
is as follows.

1. Number Systems and Introduction to Logic Concepts 30 marks


2. Truth Table 10 marks
3. Logic Diagram To or From an Expression or an Equation 10 marks
4. Boolean Algebra 10 marks
5. De Morgan's Theorem 10 marks
6. Karnaugh Map 10 marks
7. Trace Table 10 marks
8. Decision Table 20 marks
9. System Flowchart 20 marks
10. Program Flowchart 30 marks
Total 160 marks

Please note that the number systems and part of the logic concepts sections
will be tested on the computer and will consist of short questions, such as
multiple choice and fill in the blank.

The practical questions will appear on the computer and the answer must be
written on paper using a blue or black pen. The following will be required for
the examination:
 draw one truth table
 one logic diagram from an expression or equation, or derive the expression
from the logic diagram
 simplify two Boolean algebraic equations
 simplify two equations using De Morgan's theorem
 draw one Karnaugh Map
 one Decision table
 one System flowchart
 one Program flowchart
 one Trace table.

The practical questions asked in the examinations differ from the exercise
questions. The examination will test understanding and application of the
knowledge learned from all the examples and exercises.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 167 of 170
References

 Sprankle, M. & Hubbard, J. 2012. Problem solving and programming


concepts. 9th edition. New Jersey: Prentice Hall.

 http://www.allaboutcircuits.com/vol_4/chpt_7/8.html

 http://encyclopedia2.thefreedictionary.com/Boolean+algebra+(logic)

 http://www.allaboutcircuits.com/vol_4/chpt_7/9.html

 http://www.ams.org/featurecolumn/archive/venn.html

 http://www.hci.com.au/hcisite2/toolkit/flowchar.htm

 http://www.edrawsoft.com/flow-chart-design.php

 http://www.wiley.com/college/busin/icmis/oakman/outline/chap05/slides/sy
mbols.htm

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 168 of 170
Processing and Logic Concepts – Exercise Checklist

Name
Module Start Date

Section Date Checked Lecturer Sign


1.5 Exercises
1.6 Revision questions
2.4 Exercises
2.5 Revision questions
3.6 Exercises
3.7 Revision questions
4.4 Exercises
4.5 Revision questions
5.4 Exercises
5.5 Revision questions
6.7 Exercises
6.8 Revision questions
7.6 Exercises
7.7 Revision questions
8.12 Exercises
8.13 Revision questions
9.5 Exercises
9.6 Revision questions
Test Your Knowledge

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 169 of 170
Evaluation Form

How would you evaluate the learning manual?


Place a  or  in one of the five squares that best indicates your choice. Your
response will help us to improve the quality of the learning manuals and
modules and will be much appreciated.

Very
Poor Fair Good Excellent
poor
The learning manual is clear and
understandable.
The text material is clear and understandable.
The exercises help you to grasp the module
material.
The projects help you to understand the module
material.
You know what to expect in the exam.
The practical exercises test your knowledge and
ability.
Your lecturer was able to help you.

What did you most enjoy?


__________________________________________________

What did you least enjoy?


__________________________________________________

General comments (what would you add, leave out, etc.).

Please note any errors that you found in the learning manual.

Campus: ________________ Lecturer: _____________ Date: ___________

Thank you for completing the evaluation form. Please remove this evaluation
form and return it to your lecturer.

MLPL181-01 Processing and Logic Concepts Learning Manual | V1.1 Mar 2018 Page 170 of 170
CTI is part of Pearson, the world’s leading learning company. Pearson is the corporate owner, not a registered
provider nor conferrer of qualifications in South Africa. CTI Education Group (Pty) Ltd. is registered with
the Department of Higher Education and Training as a private higher education institution under the
Higher Education Act, 101, of 1997. Registration Certificate number: 2004/HE07/004. www.cti.ac.za.

Processing and Logic Concepts Learning manual | 2017 V1.0

Page 1 of 1

You might also like