Chapter10h PDF
Chapter10h PDF
10
OPTION 2
THE INTERRELATIONSHIP BETWEEN
SOFTWARE AND HARDWARE
In this option, we examine the basis of digital computer hardware; data, storage and
processing. We consider the manner in which data is represented within the computer.
Different data types require different methods of binary representation; all are based
on the binary number system. We then examine the circuits that allow us to store and
process this data. Logic gates are the building blocks for integrated circuits. What are
logic gates and how are they combined to perform new and varied functions? We
answer these questions and design some simple integrated circuits. In particular, we
investigate circuits used to perform binary addition and those used to store binary
data.
The final section of this option describes the programming and interfacing of
hardware devices. We examine the data streams required to provide input to various
hardware devices as well as the returned output data streams. The format and
processing required to generate and understand these data streams, is discussed. We
look at a number of practical examples where this infonnation is utilised to control
hardware devices in real world applications.
Computers can only process binary data; that is strings of zeros and ones. Considering
this fact, it seems remarkable that computers are able to perform such a broad range of
tasks. How can strings of binary digits be used to show videos, track bank account
transactions or control a production line of robots? Many people consider the
computer to be the most significant invention of all time.
Binary numbers are based on the number two thus place value is determined by
powers of two. The binary number 11 Olean be written as (1 x 23) + (1 X 22) +
(0 X 21) + (1 x 2°). In decimal, the binary number 1101 has a value of 8 + 4 + 0 + 1,
which is equal to 13. We write this as 11012 = 13 10, the subscript is used to indicate
the base used. Leading zeros have no effect on the value of a number. For example,
0001011 h is equivalent to 1011 h. Zeros between non-zero digits are required to
ensure correct place value. For example, 111 h is not the same number as 1011102 •
When using binary numbers with computer systems it is usual to retain the leading
zeros to make up numbers with a multiple of 8 bits. For example, we write 0011101lz
rather than 1110 11 2 • This is because computers deal with binary numbers of a specific
length. Generally, Binary
27=128 26=64 2 5=32 24=16 2 3=8 22=4 21=2 2°=1
binary numbers Number
are expressed in 11010111 1 1 0 1 0 1 1 1
series of 8 bits, 00101111 0 0 1 0 1 1 1 1
01110111 0 1 1 1 0 1 1 1
called a byte. Most
01011100 0 1 0 1 1 1 0 0
computers store
and process data in Fig 10.3
Binary numbers have place values based on the number two.
multiples of 8 bits;
the number of bits processed at a time is called the word length of the processor.
Common processors have word lengths of 8, 16, 32 or 64 bits.
Counting in binary
Decimal Binary Decimal Binary
As is the case in the decimal system, once 1 1 21 10101
we run out of digits we increment the 2 10 22 10110
number held to the left and set the current 3 11 23 10111
value back to zero. For example, in decimal 4 100 24 11000
we count 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5 101 25 11001
6 110 26 11010
12 ... 19,20,21. .. 29,30,31, etc. In binary,
7 111 27 11011
we only have only two digits so our 8 1000 28 11100
numbers very quickly become long. For 9 1001 29 11101
example, in binary we count 1, 10, 11, 100, 10 1010 30 11110
101, 110, 111, 1000, 1001, 1010, 1011, 11 1011 31 11111
1100, 1101, 1110, 1111, 10000, we are 12 1100 32 100000
already using five digit numbers yet in 13 1101 33 100001
14 1110 34 100010
decimal we have only reached a value of 16. 15 1111 35 100011
Fortunately, computers are particularly 16 10000 36 100100
good at storing vast amounts of data, so the 17 10001 37 100101
18 10010 38 100110
length of binary numbers is relatively
19 10011 39 100111
insignificant in computing terms. Humans, 20 10100 40 101000
on the other hand, find binary numbers
Fig lOA
difficult to accurately read and process. To Counting in binary and decimal.
simplify binary numbers for humans, we
use the hexadecimal number system.
Hexadecimal numbers
Hexadecimal numbers use the base sixteen number Decimal Binary Hexadecimal
system. Hex meaning six and dec meaning ten so 0 0000 0
hexadecimal refers to sixteen. Hexadecimal numbers 1 0001 1
are used because they greatly simplify the task of 2 0010 2
writing binary numbers yet conversion between base 2 3 0011 3
4 0100 4
and base 16 is simple. An eight digit binary number,
5 0101 5
one byte, can be written as a two digit hexadecimal 6 0110 6
number. Each sequence of four bits, called a nibble, 7 0111 7
converts neatly into a single hexadecimal digit. 8 1000 8
In base 16, we require sixteen unique symbols to use as 9 1001 9
10 1010 A
our digits. Because hexadecimal is so often used on
11 1011 B
computers, it makes sense to use symbols available on 12 1100 C
a standard keyboard. We use the sixteen symbols 0, 1, 13 1101 D
2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F as our digits. 14 1110 E
Furthermore, special symbols are often used to indicate 15 1111 F
the number following is in base 16. &H13 and Ox13 are Fig 10.5
the equivalent of 13 16, similarly &H6E and Ox6E are Decimal to Binary to
hexadecimal conversion.
equivalent to writing 6E16.
As is the case in other bases, place value is determined by the position of each digit.
The magnitude of each place value is calculated using powers of the base number. For
example 3E716 can be written as (3 x 162) + (E X 16 1) +(7 x 16°) and 50AB 16 as
(5 x 163) + (0 X 162) + (A X 16 1) +(B x 16°).
II
",~,,~~~~~~: ~~1~>';
GROUP TASK Activity
Although not strictly required in this course, base 8 or octal numbers are
often used in conjunction with computer systems. Make up a table of
octal numbers compared with their binary equivalents. Why do you think
octal numbers would be of use in regard to computers?
CHARACTER REPRESENTATION
Characters must be represented using binary code if they are to be stored and
processed by computers. There are two types of characters that require representation,
printable characters and non-printable characters. The printable characters include all
the upper and lower case letters of the English alphabet together with numbers,
punctuation marks and some other special characters such as the percent and dollar
sign. In addition there are thousands of characters which form part of the numerous
languages throughout the world. Finally there are non-printable characters which are
often called control characters. These characters are not displayed on the screen but
rather are used to perform commonly required functions. For example, backspace and
delete are generally used to remove data, carriage returns and linefeed characters
influence formatting, and acknowledge (ACK) and negative acknowledge (NAK)
characters are used for communication.
There are various methods used for coding characters into binary. The most common
methods are ASCII (American Standard Code for Information Interchange) and
Unicode. In the past other coding systems such EBCDIC (Extended Binary Coded
Decimal Interchange Code) were used. Note: EBCDIC is pronounced eb-sih-dik.
Unicode is the current standard as it includes characters and symbols for all current
languages. In addition Unicode includes all of the original ASCII character set. In the
next section, we examine ASCII and Unicode in more detail.
ASCII Code
ASCII is an acronym for American Standard Code for Char Dec Char Dec
NUL 0 @ 64
Information Interchange and is pronounced ass-kee. ASCII SOH 1 A 65
is a seven-bit code, which means there are 128 different STX 2 B 66
characters in the standard ASCII character set. ETX 3 C 67
EOT 4 D 68
ENQ 5 E 69
Many extensions to the standard ASCII character set ACK 6 F 70
emerged over the years; until recently most of these were 8 BEL 7 G 71
bit codes. By extending the code from 7 to 8 bits, another BS 8 H 72
HT 9 I 73
128 characters can be represented. Various different LF 10 J 74
extended ASCII systems arose during the 1980s until the VT 11 K 75
FF 12 L 76
ISO Latin 1 system became the defacto standard. ISO Latin CR 13 M 77
1 is another 8-bit system that includes the standard ASCII SO 14 N 78
character set. The International Standards Organization S1 15 0 79
DLE 16 P 80
developed this standard for use on the World Wide Web. DCI 17 Q 81
All these 8-bit systems use values above 127 to represent DC2 18 R 82
DC3 19 S 83
various foreign language, graphical and mathematical DC4 20 T 84
characters. For example, the character Yz in ISO Latin 1 uses NAK 21 U 85
SYN 22 V 86
code 189. The ISO Latin 1 codes together with ASCII are ETB 23 W 87
incorporated within the modem Unicode system. Therefore, CAN 24 X 88
code 189 in Unicode also represents the character Yz. The EM 25 Y 89
SUB 26 Z 90
standard ASCII codes shown in Fig 10.10 are correct for ESC 27 [ 91
both ISO Latin 1 and Unicode. FS 28 \ 92
GS 29 1 93
Standard ASCII has been developed to simplify the process RS 30 A
94
US 31 95
of sorting. Notice that the code for 'A' is less than 'B' is Space 32 96
less than 'c' and so on. Sorting alphabetically can be ! 33 a 97
" 34 b 98
accomplished using the numerical ASCII codes. 'A' has an # 35 c 99
ASCII value of 65 or 1000001 in binary, 'a' has a code of $ 36 d 100
97 or 1100001 in binary. Each capital letter has an ASCII % 37 e 101
& 38 f 102
code 32 less than its lower case equivalent. This difference 39 g 103
of 32 affects the value of the second highest order bit from a ( 40 h 104
) 41 i 105
o to a L * 42 j 106
+ 43 k 107
44 1 108
Consider the following: - 45 ill 109
46 Ii 110
I 47 0 111
0 48 P 112
The word 'HELLO' coded in ASCII is 72, 69, 76, 76, 79. 1 49 q 113
The 7 bit ASCII equivalent is 1001000, 1000101, 1001100, 2 50 r 114
1001100, 1001111. 3 51 s 115
4 52 t 116
The lower case word 'hello' can be similarly coded as 104, 5 53 u 117
6 54 v 118
101, 108, 108, Ill. In binary, we get 1101000, 1100101, 7 55 w 119
1101100, 1101100, 110111 L 8 56 x 120
9 57 y 121
Notice that the last 5 bits of each character are the same in : 58 z 122
upper and lower case.
59 r 123
< 60 J 124
= 61 } 125
> 62 - 126
GROUP TASK Discussion ? 63 DEL 127
Explain how the above situation can assist
Fig 10.10
when sorting and searching strings of
The ASCII character set.
characters.
Unicode
Unicode specifies a unique number for every character in every language. Prior to the
introduction and acceptance of Unicode in the 19908 there were many different
coding systems in use for different languages. This meant that many codes referred to
quite different characters and hence global communication of text in electronic form
was difficult and often involved complex conversion. Currently Unicode is the global
standard for coding characters. New characters and languages, including ancient
scripts, are continually being added to the Unicode standard. The current standard
including all coded characters is available to all at www.unicode.org. Once a code is
assigned to a particular character then it will never change. This guarantee means any
text coded using Unicode will be readable forever by any Unicode aware software.
To represent every current and future character in any language clearly requires a
large and complex system. The Unicode system is based on a total of 17 code planes.
Each code plane is 16-bits long; therefore each plane can include up to 2 16=65536
different characters. A total of around 1 million unique characters can be represented.
The first plane, plane 0, is called the Basic Multilingual Plane or BMP. The 65536
code points on the BMP include all the characters for most modem languages in use
today. The remaining 16 code planes are largely unused apart from some ancient
languages and various specialist symbols.
Within the 16-bit Basic Multilingual Plane (BMP) are aU the ASCII characters whose
code points are identical to their corresponding ASCII codes. For example, an upper
case "A" uses code 65 (or 41 16) in both ASCII and Unicode. Many of the earlier ISO
Latin 1 codes are also identical. Furthermore many characters from other languages
have been assigned codes so that conversion between older systems and Unicode is
straightforward.
GROUP TASK Practical Activity
In Microsoft Word any character can be displayed by entering its Unicode
...
hexadecimal code point value followed by Alt-x. Type your name using
this "Alt-x" system of data entry.
The Unicode standard recommends that code points should be specified using "U+"
followed by the hexadecimal value of the character, so capital "A" is specified as
"U+0041". As the BMP is plane 0 then 16-bit values (4 hexadecimal digits) are
assumed to be from the BMP. Characters from planes 1 to 16 are expressed using an
extra one or two hexadecimal digits. For example "U+IFOA1" through to
"U+ 1FODF" are characters representing playing cards, i.e. through to
The leading 1 means these codes are found on plane 1.
There are three Unicode standards for representing text namely, UTF-8, UTF-16 and
UTF-32, which unsurprisingly use 8-bits, 16-bits and 32-bits respectively to represent
characters. UTF-8 is within the majority of web page files, UTF-16 is widely used
within many desktop applications and UTF-32 is currently rarely used. At first glance
these usage comments may appear strange as the range of Unicode characters is from
0 16 up to 1OFFFF 16. The maximum value of lOFFFF 16 includes 6 hexadecimal digits
which correspond to 24-bits so surely 8~bits or 16-bits are insufficient? Clearly the
encoding system cannot use just 8-bits or even 16-bits to represent all the possible
Unicode code points. To overcome this problem both UTF-8 and UTF-16 use
multiples of 8-bits (or 16-bits) to represent many of the less commonly used and
numerically larger code points. This means the more common characters can be stored
much more economically than is the case with UTF-32.
The Unicode code points range from 0 16 up to 10FFFF 16. UTF-8 encoding requires
from one to four bytes to represent each possible Unicode code point. All the ASCII
characters require a single byte and their codes are identical to the corresponding
ASCII code which is a significant advantage over UTF-16.
U+OOOO to
U+OO7F
o to 1111111 1 to 7 Oxxxxxxx
U+0080 to
10000000 to 11111111111 8 to 11 110xxxxx 10xxxxxx
U+07FF
Notice that each of the multiple byte UTF-8 encodings begins with the same number
of 1s as there are bytes in the encoding. This feature allows software to determine the
byte length of each encoded character as it is being read. In addition all subsequent
bytes in a multi-byte encoding commence with 10. This removes all ambiguity as all
bytes beginning with a zero are single bytes (same as ASCII), all bytes commencing
with 11 are the start of a multi-byte encoding and all bytes commencing with 10 are
subsequent bytes within a multi-byte encoding.
'ill An upper case "A" is code point U+0041 (65 in decimal) which is 1000001 in
binary and would be stored in a UTF -8 file as the single byte 01000001 2 which is
simply 41 16.
fI The Greek letter pi "11:" is code point U+03CO (960 in decimal) which is in the
range U+0080 to U+07FF and is 1111000000 in binary. From Fig 10.11 the
required UTF -8 encoding is 110xxxxx 10xxxxxx which includes 11 x symbols,
however there are 10 digits in 11110000002 so we need to add a leading 0 to make
the required 11 x symbols. Therefore the character "n" in UTF -8 is represented by
11001111 100000002 which is CF80 16.
The Unicode code points range from 0 16 up to 10FFFF 16 . UTF-16 encoding uses
either one or two 16-bit sequences to represent each Unicode code point. In UTF -16
all the plane 0 (BMP) characters are simply represented identically to their code point.
For instance U+0041 is represented by the 16-bits 00000000 01000001 2 which is
0041 16 . Code points in planes 1 through to 17 require a pair of 16-bit codes or a total
of 32-bits per character. These 16-bit pairs are known as surrogates. The first is called
the lead (or high) surrogate and the second is called the trail (or low) surrogate.
Notice that for every ASCII character in UTF-l6 the leading byte is a sequence of
eight zeros. Clearly this is an inefficient use of storage, partiCUlarly for files which
contain only ASCII text. However, for processing purposes this issue is minor as for
virtually all current CPUs and RAM modules 16-bits is the smallest addressable unit.
Even if UTF-8 encoding is used then ultimately 16-bits per character are utilised
during processing.
Let us consider the system used to calculate UTF -16 surrogate values for code planes
1 to 17. These Unicode code points are in the range U+10000 to U+lOFFFF, therefore
we can immediately subtract 10000 16 from each code point and save one hexadecimal
digit (4-bits). We now have values in the range 0 16 to FFFFF 16 which in binary
requires 20-bits. If we split the 20-bits into two equal parts then each part will contain
lO-bits in the range 0 16 to 3FF 16 as 111111111 h (ten binary ones) is equal to 3FF 16.
The high 10-bits are added to D800 16 to form the lead surrogate and the remaining
low 10-bits are added to DCOO l 6 to form the trail surrogate. few example
calculations will help to explain the conversion process.
It Both upper case "A" (code point U+0041) and the Greek letter pi "n" (code point
U+03CO) are in code plane 0 as they are less than U+lOOOO. Hence in UTF-16 they
are simply represented by their code point values 0041 16 and 03C0 16 respectively.
«I The Queen of Spades character is code point U+ 1FOAD. As U+ IFOAD is greater
than U+ 10000 we need to calculate surrogates.
- First we subtract 10000 16 from IFOAD 16 which leaves FOAD 16 .
We convert FOAD 16 into binary which gives us 111100001010110h
We need this as a 20-bit number so we add leading zeros resulting m
0000111100001010110h
- Split 000011110000 10 10 11 0 b into two to create the 10-bit numbers
00001111002 and OOlOlOllOh Which in hexadecimal is 03C 16 and OAD 16 .
Add 03C 16 to D800 16 to form the lead surrogate D83C 16.
- Add OAD 16 to DC00 16 to form the trail surrogate DCAD I6 .
- Therefore U+IFOAD is represented in UTF-16 by D83CDCAD 16 which
converts to the 32-bit binary number 1101100000111100 110111001010110h .
2.,
4.
5.
12.
13.
14.
15.
INTEGER REPRESENTATION
Integers are whole numbers, both positive and Complex Numbers
negative. For example, 456, 12,0, -1 and -3965 are all
integers, 3V4, n, -2.995, 0.888... and -/2 are not Real Numbers
integers, rather they are real numbers. Integers form a
subset of the real numbers. Zero is a special integer; it
is neither positive nor negative.
We have already seen how positive integers and zero
Fig 10.12
can be represented using binary on computers. How
1ntegers are a subset of the real
do we represent negative integers using only zeros numbers, which in turn are a subset
and ones? We can't use a '-' sign directly as of the complex numbers.
computers can only work with zeros and ones. A
number of techniques have been developed. The aim of each technique is to provide a
system that allows accurate and efficient calculations to take place.
In this section, we examine two integer representation techniques:
.. Sign and modulus.
" Two's complement (and one's complement).
Sign and modulus
The sign and modulus method is perhaps the most obvious solution. We just add an
extra bit to the front of each number to represent the sign of the number. A zero is
used for positive numbers and a one for negative numbers. The modulus is the
magnitude of the number or the absolute value of the number. Mathematically the
absolute value of a number is the distance from the number to zero.
If we are using 7 bits for the modulus then the number 12 would be represented as
00001100 and -12 as 10001100. Using this system, zero can be represented in two
ways; either 10000000 or 00000000.
Using the sign and modulus method, the sign of the number is not an integral part of
the number. This means that calculations must take account of the sign bit separately
to the actual calculation. This is essentially what we do when adding or subtracting
negative numbers by hand. For example, when adding say 12 and -7 we know that
adding a negative is the same as subtracting, so we perform the calculation 12 - 7 and
get the result 5. Computers find subtraction unnecessary and hence the sign and
modulus method is not generally used on modern computers.
moment, imagine we dispense with the negative or left o 250 500 750 1000
hand side of the number line and that our positive numbers o
are finite, say with a maximum value of 1000. Imagine we
join the ends of this finite number line to form a circle (see
750 250
Fig 10.13).
Now if we move in a positive or clockwise direction our
integers increase in value. If we move in a negative or 500
anti-clockwise direction our integers decrease in value, Fig 10.13
with one important exception, zero. Moving anti- Wrapping a finite positive
clockwise from zero we would like to decrease into the number line to form a circle.
negative numbers, -1, -2, -3 and so on, instead we reach
999, 998, 997 ... These numbers are complements of their positive equivalents, in our
example the ten's complement of 1 is 999, of 2 is 998, of 3 is 997 and so on. Each of
these pairs of numbers is the same distance from zero on our circular number line.
We cannot have 999 representing both -1 and 999 so we need to develop some rules.
Let us make sure there are an equal number of positive and negative integers.
Positive's run from 0 to 499 and negatives from 999 down to 500.
Now let us test our results using normal addition. For example -3 + -5, using our ten's
complement system this becomes 997 + 995 giving us a result of 1992. If we discard
the leading 1, we get the correct answer 992, which using our system is equivalent to
-8. Let us try -6 + 19, this becomes 994 + 19 resulting in 1013. Discarding the leading
1 gives us the correct result 13.
We mentioned above that all positive two's complement numbers commence with a
zero and all negatives with a one. This information is particularly useful if we wish to
convert a two's complement number into decimal.
Using our 8-bit two's complement system -12 is represented as 11110100. Each
binary digit has a place value, commencing from the right hand side with 20=1,2 1=2,
22=4 , 23=8 , 24=16 , 25=32 , 26=64 and the -128 64 32 16 8 4 2 1 Decima!
last or left hand bit has a place value of 1 1 1 1 0 1 0 0 -12
_27= -128. The bit on the left hand side is 0 1 0 1 1 0 1 0 90
1 0 0 0 0 1 0 1 -123
often called the 'highest order bit' or the 0 0 0 0 1 1 0 1 l3
'most significant bit'. We can write
64 64
11110100 as -128 + 64 + 32 + 16 + 0 + 4 32 16 8
+ 0 + 0 which equals -12. If we were 16 8 4 4
performing many of these conversions, it 4 2 1 1 Working
116 90 5 13
is convenient to draw up a table such as - 128 - 128
the one in Fig 10.16. Add up all the - 12 - 123
positive values first and, if necessary, Fig 10.16
subtract 128 at the end. Table for converting two's complement to decimal.
Fixed-point
Fixed-point refers to the position of the decimal point. When using fIxed-point
numbers the decimal point remains in the same position for all numbers. For example,
a fIxed-point system using 16 bits may have 8 bits for the whole number part and 8
bits for the fractional part. The problem with such a system is that very large numbers
and very small numbers cannot be represented. The smallest positive number that can
be represented using two's complement and 16 bits is O.OOOOOOOlz = 0.00390625 10
and the largest is 01l11111.1111111lz = 127.9960937510.
Fixed-point numbers are not included as standard data types in most high-level
languages; rather, they are created by programmers using one of the integer data
types. Fixed-point representations are generally faster and more accurate than
floating-point, unfortunately for most applications their range is insuffIcient so
floating-point numbers are used. Many specialised applications where the range of
numbers is small yet accuracy is important will used fIxed-point representations. The
fIxed-point method is essentially the same as the two's complement system with the
decimal point shifted to an appropriate position for the particular application.
Floating-point
Floating-point numbers can be thought of as generalised fIxed-point numbers. The
position of the decimal point is encoded within the format. In this way, the decimal
point can be placed in a different position within the number. Essentially, the number
is stored using scientifIc notation. For example, in decimal 2345.678 can be written as
2.345678 x 103 , which is often written as +2.345678E+3. There are three essential
components to each number; the mantissa which in sign mantissa exponent
this case is 2.345678, the exponent which is 3 and the
sign of the number, in this case +. The value of the ~ ~ ~
exponent determines the position of the decimal point. +2.345678 X 10 3
There are a number of mathematical operations that cannot be computed, for example
division by zero and finding the square root of negative numbers. We also require a
method for representing infinity and negative infinity. As a result of not including the
leading one III the
mantissa, we also require a Infinity o 11111111 00000000000000000000000
special case for zero. Negative Infinity 1 11111111 00000000000000000000000
These special cases have Zero o00000000 00000000000000000000000
been included in the IEEE Negative Zero 1 00000000 00000000000000000000000
754 standard. Fig 10.19
Not a Number x 11111111 xxxxxxxxxxxxxxxxxxxxxxx
shows the representations
for each of these cases. Fig 10.19
Special cases in the IEEE 754 floating-point standard.
The not a number case is
used for meaningless
operations such as division by zero and square roots of negative numbers. In these
cases, an error code is often coded into the mantissa part of the number. This allows
feedback to be returned to programmers on the nature of the meaningless operation.
IEEE 754 double precisionjloating-point standard.
This standard uses 64 bits to represent
1 110 1111111 0 11 00 10000 ... 00000000
each number. A sign bit, 11 bits for I "- m ... u) \.. ../
IV -----y-- Y
the exponent and 52 bits for the
sign exponent mantissa
mantissa. (I bits) (11 bits) (52 bits)
BINARY ARITHMETIC
The four operations of addition, subtraction, mUltiplication and division can be
accomplished in binary using similar techniques as those used with decimals. Because
we have only two digits in binary, 1 and 0, these operations become simpler, we need
only know number facts involving 0 and 1. Unfortunately, performing operations on
large numbers becomes somewhat tedious, as binary numbers tend to be much longer
than their decimal equivalents.
In this section, we will examine the four arithmetic operations using two's
complement integers. Similar processes are involved when using fixed and floating-
point real numbers, however multiple computations are required. For example,
consider multiplying two decimal numbers written in scientific notation; the mantissas
are multiplied, the exponents are added, then the result is normalised so the mantissa
is between 0 and 10. Multiplication of floating-point numbers involves similar
processes.
Let us examine each of the four operations in tum:
Binary addition
When we first learnt addition in primary school, we were
-, --
taught all our basic number facts with numbers up to 10. + 0 I
For example, 5 + 3 = 8, 6 + 9 = 15, 0 + 5 = 5, etc ... ; 100
different number facts in alL In binary, we need only learn 0 0 1
a total of five number facts. In fact, the only binalY
addition number facts required are 0 + 0 = 0, 0 + 1 = 1, I 1 10
1 + 0 = 1, 1 + 1 = 10 and 1 + 1 + 1 = 11.
1+1+1=11
The method of performing addition in decimal can also be Fig 10.21
used for binary addition. Each column is added Binary addition numberfacts.
commencing with the right hand side. If the result is 10 or
11 then a 1 is carried to the next column.
2. Applying the same technique used above we get the result 11111
01011101 +
437
!
11010001 (see Fig 10.22). This result is a negative number
01110100
in 8 bit two's complement, as the leading bit is a one. How
can this be when the numbers in the question are both 11010001
positive? Let us examine the question in decimal.
Fig 10.22
0101110lz = 9310 and 011101002 = 116 10, in decimal 93 + An overflow error occurs
116 = 209. 209 is outside the range of values available in 8 if the result is outside the
bit two's complement, so the result has wrapped around allowable range.
into the negatives. (8 bit two's complement has a range
from -128 to 127). If this situation occurs in source code, an overflow run time
error would result. Programmers need to be careful that the data type chosen is able
to contain the results of any calculations within their source code.
3. This question results in a carry in the final stage of the 11
11000000 +
addition (see Fig 10.23). As we have only 8 bits to work with,
01110000
we ignore this last carry. Ignoring the final carry, in this case,
effectively causes the result to wrap around past zero. As the 00110000
result is still within the range of our two's complement Fig 10.23
system no overflow error results and the correct answer is Ignore any final carry
calculated. In decimal, this question is the equivalent of -64 + when using the two's
112 = 48. complement system.
Binary subtraction
Although binary subtraction can be performed in a similar way as we perform decimal
subtraction, computers do not use it, rather we add the negative. For example 5 - 3 is
the equivalent of 5 + -3. This process can be used to convert all subtractions to
additions. When working with two's complement binary numbers we convert the
number being subtracted to its two's complement and then add.
L 01010111- 2. 00011001-
00011100 11111011
1. Let us examine the working for this question in detail. Firstly, we need to find the
two's complement of the number being subtracted. In this case the number,
00011100, is positive as the leading bit is a zero, so we Swap I s Leave the
expect the two's complement to be negative. We can find and Os first 1
the two's complement in two ways; find the one's Find the ~I
complement and add one or scan from right to left and negative 00011100
swap l' s and Os after the first 1 is encountered. 11100100
'--y----J
Two's complement
For this question, we will use the second method.
11 1
Scanning 000 III 00 from the right hand side, we 01010111 +
encounter a 1 in the third position, leave this 1 as is and then { 11100100
add
change all the other digits. Our result is 11100100, which
is negative as expected. 00111011
Binary multiplication
The method used to multiply in binary is the same as that used for decimal.
Fortunately, in binary we only have the two digits 0 and 1. Multiplying by 0 or 1 is
certainly an easier proposition than multiplying by 0, 1,2,3,4,5,6, 7, 8 or 9.
Let us consider a simple example: 1001 x 101, which in decimal 1001x
is 9 x 5. The working for this multiplication is shown in Fig 101
10.26. Notice that each row in our working either contains all
zeros or it contains the first number in the multiplication shifted 1001
zero or more places to the left. Binary multiplication is often 00000
called 'Shift and add'. In essence, a microprocessor need not 100100
ktlow how to multiply if it is able to shift bits to the left and it 101101
can add.
Fig 10.26
We examined a number of 8086 assembler instructions in Binary multiplication
chapter 5. 8086 assembler includes a SAL and a SAR statement, can be performed like
meaning 'Shift Arithmetic Left' and 'Shift Arithmetic Right', decimal multiplication.
used in conjunction with the addition instructions ADD
(Addition) and ADC (Addition with Carry) binary multiplication is accomplished. All
microprocessors have the equivalent of these instructions hardwired as part of their
micro-code instruction set.
When performing multiplication by hand we perform
all our sub-multiplications first and then add them all
up at the end. Computers perform a shift (the
equivalent of a sub-multiplication) and add the result
to a running total. They then perform another shift
and add the result to the total, this process continues
until the multiplication is complete. Fig 10.27 shows
an algorithm that could be used to complete this
process. Binary multiplication when performed on Is Numl not No
equal to O?
computers is often called "shift and add".
Binary division
Division in binary can be perfonned using the same techniques used with decimals.
Let us examine one common technique with a decimal example. We will then emulate
this technique in binary.
Let us consider 6925 . .;- 7. The working for this division is shown in 989
Fig 10.2B. The result is 989 with a remainder of 2, for our purposes, 7)6925
we are interested in integer division so we will ignore the 63
remainder. 62
56
Firstly, we ask ourselves how many times 7 goes into 6, it doesn't, 65
we could write a 0 up the top. We then ask does 7 go into 69, yes, 9 63
times, so we write a nine up the top. In fact, what we are doing is
2
calculating the number of times 7 goes into 6900. The answer is
Fig 10.28
900, we write a 9 in the hundreds column. We then perfonn the Decimal division
subtraction 69 - 63, this equals 6. We then bring down the 2 from example.
above and ask how many times 7 goes into 62, which is really how
many times does 7 go into 620. The answer is 80 times so we write an 8 in the tens
column. The process continues in this way until all digits have been brought down
from above.
Now let us consider this technique with a binary example, 1001
111010...;- 110. Does 110 go into 1, no, does 110 go into 11, no. 110)111010
We now ask does 110 go into 111, yes it goes in once, in fact it 110
will either not go in or it will go in once. Because we are working 1010
in binary this is always the case. Subtracting 110 from 111 leaves 110
us with 1. Actually, we are perfonning the binary subtraction 100
111000 - 110000, which is perfonned by computers by adding the Fig 10.29
negative. We bring down the next digit, a zero, and so on until we Binary division
have a number greater than 110, namely 1010. Subtracting 110 example.
leaves a remainder of 100. In decimal, we have perfonned the
division 58 . .;- 6 = 9 remainder 4.
Let us now consider the processes used by computers to perform division. Division is
the most complex of the four basic arithmetic operations and there are many complex
ways of performing binary division.
One common, yet complex, method involves the use of partial fractions. Using this
method the division is viewed as a fraction. For example, 58 -;- 6 is equivalent to 58/6.
This fraction is broken down into a series of partial fractions with denominators that
are all powers of two e.g. 58/6 "" 58/8 + 58/32 + 58/128 + 58/512 + 58/2048 +
58/8192. Evaluating each of these partial fractions in binary is straightforward.
Dividing a binary number by 2 is accomplished by shifting 1 position to the right.
Dividing by 4, shift 2 positions, dividing by 8, shift 3 positions, and so on. Adding up
each of these partial results yields the answer to the original division. Calculating the
partial fractions is a mathematical process that is beyond the scope of this course.
Nevertheless, it is important to realise that this method exists and is often used.
Another common method of performing BEGIN BinaryDivision
binary division on computers emulates the Get Num 1,Num2
. d h' Divisor = Num2
technIques use on t e preVIOUS page to WHILE Left hand bit of divisor is 0
perform division by hand. Fig 10.30 describes Shift Divisor left
an algorithm that could be used to implement END WHILE
this technique. This technique is often called Remainder = Num 1
'shift and subtract'. Initially the divisor is Quotient = 0
WHILE Divisor:2 Num2
shifted to the left of the available bits. We Shift Quotient left
then progressively shift the divisor to the IF Remainder:2 Divisor THEN
right. After each shift, we compare its value Remainder = Remainder - Divisor
with the remainder. If the remainder is larger, Quotient = Quotient + 1
ENDIF
we subtract and record a one in the quotient. Shift Divisor right
Eventually, the divisor will hold a value ENDWHILE
smaller than the original Num2 input, END BinaryDivision
signifying the process is finished. Fig 10.30
Algorithm for binary division.
Fig 10.31 shows a desk check of this
algorithm using 1110 10 and 110 as the initial Initially Numl is set to 00111010 and
inputs. In other words, we are performing the Num2 to 00000110 if we use an 8 bit
decimal division 58 -;- 6 in binary. system.
Divisor Remainder Quotient
GROUP TASK
00000110
Activity
00001100
00011000
Perform a desk check of the 'shift and 00110000
subtract' algorithm shown in Fig 10.30 using
01100000
111100 and 101 as the inputs. This is the
equivalent of 60 -;- 5 in decimal. 11000000 00111010 00000000
01100000 00000000
00110000 00000000
GROUP TASK
00011000 00001010 00000001
Investigation
00001100 00000010
00000110 00000100
Dividing by powers of 2 is simple in binary. 00000011 00000100 00001001
Do you agree wiLli this statement? Explain
Fig 10.31
using a number of examples.
Desk check a/the 'shift and subtract'
binary division algorithm.
Question 1.
A programming language defines the Byte data type as follows:
Byte Data Type
Unsigned 8-bit (I-byte) integer ranging in value from 0 through 255
The language also includes a HexO function defined as follows:
Hex Function
Returns a string representing the hexadecimal value of a number
The following code in this language is executed:
10 Define A, B, C as Byte data type
20 A = 180
30 B = 9
40 C = A I B
50 Println Hex(A} + " divided by" + Hex{B} + ({ equals" + Hex(C)
(a) Line 10, 20 and 30 have executed. Determine the binary numbers held in
memory representing the contents of variable A and variable B. Show an
working.
(b) Manually perform the binary division the CPU would carry out to execute line
40. Show all working.
(c) Determine the output printed when line 50 is executed. Show all working.
(d) A new version of the same programming language redefines the Byte data type
as follows:
Byte Data Type
8-bit (1-byte) signed two's complement integer
Discuss possible affects of this data type change when the code above IS
executed.
Question 2.
The Single data type in a language complies with the IEEE 754 32-bit Single Precision
Floating Point standard.
(a) A variable of type Single currently contains the decimal value 20. The memory
location associated with this variable contains the following 32 bits:
01000001101000000000000000000000
Explain how the bit pattern above represents the decimal value 20. Show all
working.
(b) The Integer data type in this language is defined as follows:
Integer Data Type
32-bit (4-bytes) signed two's complement integer
Compare the Single and Integer data types in terms of their precision, range and
efficiency of processing.
Suggested solutions
Qu.estion 1.
(a) 'A' contains 180 which we 'B' contains 9 which we
convert into binary: convert into binary:
180 9
~
2 0 ~ 2 1
-- --
90 4
2 0 2 0
--
~
--
45 2
2 1 2 0
--
22 1
2 0 2 1
--
11 0
2 1
~
(Check: 8 + 1 = 9 ~)
5
2 1
--
2
2 0
--
1
~
2 1
--
0
(Check: 128 + 32 + 16 + 4 = 180 ~)
Therefore the content of variable A is represented in memory as 10110100 and
the content of variable 'B' is represented in memory as 00001001.
(b) 10100
1001 ) 10110100
1001
1001
1001
000
(Check: 16 + 4 = 20 = 180/ 9 ~)
(c) A= 1011 01002 = (8+2+1)(4) =B416
B = 0000 100h = (0) (8+1) = 9 16
C = 0001 0100 2 = (1) (4) = 14 16
Therefore the output from line 50 is "B4 divided by 9 equals 14".
(d) There are two possible consequences of the change from unsigned to signed
two's complement. Both problems are with the number 180 stored in variable A
within the code. 180 is within the range of an unsigned byte (0 to 255) but is
outside the range of a signed two's complement byte (-128 to 127).
During execution a runtime error may occur if the programming language
detects the now out of range assignment of 180 to the Byte variable A.
The language may allow 180 and let it overflow such that it will be interpreted
as a negative number. This means that A (which holds the binary number 1011
0100) will not be interpreted correctly as 180. Because the leftmost bit is a 1,
the value would be interpreted instead as a negative number. Using two's
complement the decimal value of 1011 0100 = -128 + 32 + 16 + 4 = -76. This
will have obvious processing consequences in the code~ since the intended
number is not being used.
Question 2.
(a) Sign = 0
Exponent = 1000 0011
Mantissa = 01000000000000
With a bias of 127, the exponent = (128 + 2 + 1) - 127 = 131 - 127 = 4
With normalisation (add the leading 1), the mantissa = 1.01
Therefore the binary value = 1.01 x 24 = 10100
Which in decimal = 16 + 4 = 20
(b) Integer values represented as 2's complement signed integers using 4 bytes (32
bits) can take values from _2 31 to 2 31 - 1. Because they are integer values, all
whole numbers in this range can be represented exactly as sums of powers of 2,
with no need for approximations.
On the other hand, the maximum value that can be represented in a 4 byte
floating point number is
=011111110111111. .... 1
= +2(254-127) x 1.1111111. .. 1
"'" 2127 x 2
"'" 2 128
2 128 is clearly significantly larger than the maximum value of 231 - 1 able to be
expressed using the integer representation.
If integer representation is used, only whole numbers can be represented, no
fractional values are possible. If floating point representation is used, then it is
possible to represent a whole range of fractional values.
However, if floating point representation is used, there are a whole range of
numbers that cannot be expressed exactly (such as 9.45). All of these numbers
are therefore expressed as an approximation using all 23 binary places available
in the mantissa to provide a value very close to that required.
This can give rise to some unexpected results when comparing integer and
floating values, where it cannot be assumed that the integer representation is
exactly equal to the floating point value, which may be an approximation to the
required value as a result of previous calculations.
In terms of processing time required, arithmetic using floating point numbers is
nowhere near as straightforward or as efficient as arithmetic using binary
integers. In fact floating point arithmetic is performed by a special co-processor
chip (or floating point unit) as the mantissa and exponent need to be considered
separately and processed differently.
Notes
• In question 1 (a) when using the divide by 2 conversion method the answer is read
from top to bottom. Of course, alternative methods of conversion are equally valid.
• The suggested solutions for questions 1 (a) and (b) includes a check to ensure
correctness. This is easy to achieve and hence well worth the time it takes,
particularly when the question is given in decimal.
• It is important to show all working for these type of questions as often marks will
be awarded for correct working and in addition, working often prevents trivial
errors being made.
SET10C
AND gate
This circuit emulates the logical AND
°
operator. If is false and 1 is true then both
inputs must be true for the resulting output to
A
0
0
B
0
1
C
0
0
be true. The two switches A and Bare 1 0 0
1 1 1
connected in series; as a result, both switches
must be down for the globe to bum. Fig 10.33
AND gate. Both A and B must
The truth table contains two inputs, A and B, be 1 for the light to burn.
as a result there are 4 possible combinations
resulting in 4 rows in the table. It is convenient to write down each row in a logical
sequence. The combination of columns A and B is written in ascending binary order;
namely 00,01, 10, 11 which is the decimal equivalent ofO, 1,2,3.
Each logic gate is represented on circuit diagrams as a symbol. lr--·-·_·_·
Input 1
AND gates use a rectangle with a rounded right hand side. For
most purposes, two inputs are sufficient, however it is possible to ; :AQ-':
~ ; C
, B ; ,
design AND circuits using any number of inputs; 2, 3 or 4 inputs
are common. Fig 10.34 shows the symbol used to represent AND Fig 10.34
The symbol for an
gates. The logical expression A AND B is written in Boolean AND gate.
algebra notation as A·B or just AB.
OR gate
Either A or B must be true for the output to be
true. The two switches are connected in
parallel, therefore if either switch is in the A B C
down or on position the globe will light. It is 0 0 0
0 1 1
possible to have more than two inputs into an
1 0 1
~D-c
OR gate. As long as one or more inputs are 1 1 1
true (l) the output will also be true (l ).
Fig 10.35
Conversely, if all the inputs are false (0) then
OR gate. Either A or B must be
the output will be false (0). The logical 1 for the light to burn.
expression A OR B is written in Boolean
algebra notation as A+B.
NOT gate
The NOT gate is used to reverse the input; as
a result NOT gates are often called inverters.
If the input is false (0) then the output will be B
true (l) and vice versa. It is only possible to
have one input into a NOT gate. Remember
that in our representation using switches,
§±§ o
1
B
1
0
battery and globe that a switch in the up A-{>o-B
position is off (0 or false) and a switch in the Fig 10.36
down position is on (1 or true). NOT(A) is NOT gate. When switch A is up (0) the
globe burns (1). When switch A is
written in Boolean algebra notation as A . down (1) the globe does not burn (0).
The symbol for a NOT gate is a small hollow
circle. The triangle preceding the circle is really a buffer. Buffers are used to
synchronise timing, often your circuit will need to wait for the next input. Buffers can
be used to accomplish this task. NOT gates require buffers to ensure correct timing.
NAND gate
NAND is short for NOT AND, in other words a NAND gate
is logically the same as an AND gate fonowed by a NOT ~O{>o-c
gate. The output from a two input NAND gate is the opposite Fig 10.37
of that from an AND gate, that is 1110 rather than 0001. The A NAND gate is the
ability to use the output from one logic gate as the input for equivalent of an AND gate
followed by a NOT gate.
another provides the ability to combine gates to perform new
and varied tasks. The symbol for a NAND gate A
is the AND symbol followed by the NOT
symbol or in Boolean algebra notation as AB.
c
A B C
In logic terms, the output from a NAND gate is
0 0 1
true if all inputs are not true. This logical 0 1 1
explanation holds true regardless of the 1 0 1
number of inputs into the NAND gate. Most
NAND gates contain 2,3 or 4 inputs.
~D-c 1 1 0
Fig 10.38
NAND gates are perhaps the most useful logic NAND gate. All other logic gates can
be simulated using NAND gates.
gate. It is possible to simulate all other logic
gates using combinations of NAND gates. As a
result, microprocessors could be designed
using NAND gates exclusively. Although this
is possible, it is not the most efficient method. c A B C
In the next section, we will attempt to create 0 0 1
0 1 0
each of the other logic gates using only NAND 1 0 0
gates. 1 1 0
NOR gate ~D-c
Fig 10.39
NOR means NOT OR, a NOR gate is NOR gate. Both A and B must
equivalent to an OR gate followed by a NOT be 0 for the light to burn.
gate. In Boolean algebra notation NOR is
written as A + B . Fig 10.39 shows a possible
circuit together with the truth table and symbol
for the NOR gate. All inputs must be false for c A B C
the output to be true. 0 0 0
0 1 1
XORgate 1 0 1
1 1 0
XOR is short for exclusive OR. This means
that precisely one input must be 1 (true) for the ~jD-c
Fig 10.40
output to be 1 (true). A XOR B is written in
XOR gate. Exactly one input must
Boolean algebra notation as A EB B. In some be true for the output to be true.
literature, XOR is called EOR; the terms are
interchangeable. In this text, we will use the
termXOR.
CIRCUIT DESIGN
Combinations of the above logic gates can be used to solve new problems. Problems
in circuit design are normally presented in the form of inputs and required outputs,
essentially a truth table. Computer Aided Design software is available to assist in the
design of circuits, in fact it would be impossible for today's microprocessors to have
been created without the use of computer aided circuit design tools!
The process of developing new circuit designs is cyclical in nature. As is the case with
software solutions, there are often many ways to solve the same problem. The aim is
to find the most efficient and elegant solution. This often involves a process of
evolutionary refmement. In this course, we need only consider the logical level of
electronic circuit design. Electrical engineers need to consider many other factors
when solving real world problems.
OR gate
This gate requires a little more thought. Let us A B NAND OR
examine the truth tables for both the NAND and 0 0 1 0
OR gates side by side (see Fig 10.44). Inputs of 01 0 1 1 1
and 10 result in the same outputs of 1 from both 1 0 1 1
1 1 0 1
NAND and OR gates, however the outputs from
00 and 11 are reversed. If we can invert the inputs Fig 10.44
Truth table for NAND
before they reach the NAND gate, we may get the
and OR side-by-side.
result we desire.
In logical terms we perform (NOT(A)) NAND Input A
(NOT(B)). As we don't have any NOT gates we Output
substitute each NOT for our NAND equivalent, InputB
hence our logical statement becomes (A NAND
A) NAND (B NAND B). We require three NAND
gates to produce a single OR gate. Fig 10.45
shows the circuit diagram and pin connections
using our NAND IC.
XORgate
This gate is rather more difficult. Let us first
examine the truth table for the XOR gate, the
outputs are 0110. Similar in many ways to an OR
gate except 1 and 1 results in an output of 0 rather Hg 10.45
than 1. If we consider the last sentence and OR gate produced using 3 NAND gates.
attempt to write it as a logical statement we get
something like: A or B but not A and B. This can Input A
be written as (A OR B) AND NOT(A AND B). Input B _--+-1
Output
Now NOT(A AND B) is the opposite of an AND
gate, which fortunately is a NAND gate; our
statement becomes (A OR B) AND (A NAND B). Fig 10.46
XOR gate produced using
Fig 10.46 shows our progress as a circuit diagram.
3 different gates.
We could replace the OR and AND gate in this
solution with the NAND representations we developed above, this results in the
circuit design shown in Fig 10.47. Unfortunately, this solution requires 6 NAND
gates and each of our ICs
contains only 4 NAND gates. It InputA
would be convenient and more
Output
efficient to find a solution using Input B
just 4 NAND gates.
Boolean algebra provides a Fig 10.47
mathematical technique for XOR gate produced using 6 NAND gates.
simplifying and/or rearranging
circuit designs such as this. The following pages describe the basics of Boolean
algebra and how it can be used to optimise the design of circuits.
BOOLEAN ALGEBRA
Boolean algebra was fIrst developed by the English
mathematician George Boole around 1850. Coincidentally,
this was about the same time Charles Babbage was working
on his Analytical Engine, the forefather of today's
computers. Boolean algebra is used to describe logical
propositions where the outcome is either true or false. The
application of Boolean algebra to circuit design has enabled
the design of today's effIcient circuits containing many
millions of logic gates.
Fig 10.48
In Boolean algebra notation, variables can hold values of 0 George Boole (1815-64)
(false) or 1 (true). There are three operations NOT, OR and
AND. NOT A is denoted as A, A OR B is denoted A+B and A AND B is denoted
A· B or just AB. A further notation has been added for XOR, A XOR B is denoted
AE!3B.
Boole, along with one of his contemporaries, Augustus DeMorgan developed and
proved the following laws of Boolean algebra:
la. A+B=B+A 4a. A+A=A 7a. A +A=l
lb. AB=BA 4b. AA=A 7b. AA=O
2a. (A+B)+C=A+(B+C) 5a. O+A=A 8a. A+ A B=A+B
2b. (AB)C=A(BC) 5b. OA=O 8b. A( A +B)=AB
3a. A(B+C)=AB+AC 6a. I+A=l DeMorgan's Theorem
3b. A+(BC)=(A+B)(A+C) 6b. lA=A -- --
9a. (A+B)=A B
- - -
9b. (AB)=A + B
Let us use these laws to help simplify our XOR problem into a series of NAND gates.
At this stage it is not necessary to be able to reproduce such working rather it is
suffIcient to be able to follow each step in the working based on the above laws of
Boolean algebra. Initially we described XOR as A OR B AND NOT(A AND B):
A E!3 B = (A + B)AB (definition ofXOR gate)
= AB(A+B) (usinglaw1b.) InputApgo
output
= ABA + ABB (using law 3a.) Input B
- -
= AAB + BAB (using law 1b.)
Fig 10.49
= AAB + BAB (applying not twice). XOR gate using only 4 NAND gates.
Input B --+l~
Implementing this Boolean expression as a
circuit diagram requires 4 NAND logic gates
1----1--1-- Output
(see Fig 10.49). As a result, we are able to
use a single IC; remember each of our ICs
contains 4 NAND gates. Fig 10.50 shows the
wiring for our IC.
Fig 10.50
XOR gate created using an Ie
containing 4 NAND gates.
Let us examine the above laws of Boolean algebra in more detail. The first thing we
notice is that many of the laws are the same as regular algebra. In particular laws 1a,
1b, 2a, 2b, 3a, 5a, 5b and 6b. This leaves the following set of new laws to learn:
3b. A+(B C)=(A+B) (A+C)
4a. A+A=A
4b. AA=A
6a. l+A=l
7a. A+A=l
7b. AA=O
8a. A+AB=A+B
8b. A(A+B)=AB
- - --
9a. (A+B)=Ay
9b. (AB)=A+B
Let us briefly run through each of these laws commencing with the simpler laws first.
• 4a. A+A=A. In words this law means "A or A will equal A A A A+A
regardless of the value of A". Fig 10.51 shows the truth table 0 0 0
which confirms that when A=O then A+A also equals 0, and 1 1 1
when A is 1 then A+A also equals 1 based on our earlier OR Fig 10.51
gate description. In practice this rule is often extended in a Law 4a truth table
variety of ways such as, AB + AB = AB, A+A+A+A = A and
even in reverse when an extra term is needed such as replacing AB with AB + AB
within an expression.
A A AA
• 4b. AA=A. This law means "A and A always equals A 0 0 0
regardless of the value of A". The truth table in Fig 10.52 1 1 1
confirms this to be true based on our previous AND gate Fig 10.52
definition and truth table. Can also be extended so it is also true Law 4b truth table
to say that AAAAA = A or in combination with rule 1b it is true
1 A l+A
that ABBAABAB = AAAABBBB = AB.
1 0 1
• 6a. l+A=1. This means when 1 is 'OR'ed with anything the 1 1 1
result is always 1. This is a very useful rule as it often allows a Fig 10.53
whole string of complex terms to be reduced to 1. For example, Law 6a truth table
the expression AB+BD+AD+l = (AB+BD+AD)+l = 1.
A A A+A AA
• 7a. A +A=1. If two opposite Boolean values are 'OR'ed 0 1 1 0
the result is always 1 (true). 1 0 1 0
• 7b. A A=O. If two opposite Boolean values are Fig 10.54
'AND' ed the result is always 0 (false). Law 7a and 7b truth table
Il'l 8a. A+ A B=A+B. The fonowing mathematical proof and the truth table in Fig
10.55 shows the law to be true.
RHS = A+B
A+B(l) (as 1B=B law 6b) A B A AB A+AB A+B
0 0 1 0 0 0
A+B(A+ A) (using law 7a) 0 1 1 1 1 1
A+AB+ A B (expanding using law 3a) 1 0 0 0 1 1
1 1 0 0 1 1
A(l +B)+ A B (factoring using law 3a)
Fig 10.55
A(l)+ A B (using law 6a) Law 8a truth table
A+ A B (using law 6b)
LHS
* 8b. A( A +B)=AB. The following mathematical proof and the truth table in Fig
10.56 shows the law to be true. - -
A B A A+B A(A+B) AB
LHS = A(A +B) 0 0 1 1 0 0
AA +AB (expanding using law 3a) 0 1 1 1 0 0
O+AB (using law 7b) 1 0 0 0 0 0
1 1 0 1 1 1
AB (using law 5a)
Fig 10.56
RHS
Law 8b truth table
• 9a. (A + B )= A Band 9b. (AB)= A + B . These are DeMorgan' s theorems and are
the basis for the "Sum of Products" and "Products of Sums" techniques we
examine in the next section. In words theorem 9a means the reverse of 'OR'ing is
the same as reversing each value and then 'AND'ing them. And 9b means the
reverse of 'AND'ing is reversing then 'OR'ing. These theorems are useful when
you wish to convert OR gates to AND gates or vice versa. The following truth
tables in Fig 10.57 shows both theorems to be true.
A B A B A+B AB AB A+B
0 0 1 1 1 1 1 1
0 1 1 0 0 0 1 1
1 0 0 1 0 0 1 1
1 1 0 0 0 0 0 0
Fig 10.57
DeMorgan's Theorem 9a and 9b truth tables
Question 1.
A student has designed the following two circuits.
Circuit 1. Circuit 2.
A --.,.--1 A
x
B
B x
(a) Complete truth tables to prove both the above circuits produce the same output.
Include each letter on the circuits as a column in the truth tables.
(b) Design a simpler circuit that produces the same output as the above circuits.
Question 2.
A B C Output
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
Create a circuit diagram based on the above truth table.
Question 3.
The following circuit uses six NAND gates.
A
B
x
C-----l
Suggested solutions
Question 1.
(a) Circuit 1. Circuit 2.
A B C D X A B E F G X
0 0 1 0 1 0 0 1 1 1 1
0 1 1 0 1 0 1 1 0 0 1
1 0 0 0 0 1 0 0 1 0 0
1 1 0 1 1 1 1 0 0 0 1
The X columns are the same therefore both circuits are logically the same as
they output the same values for the equivalent inputs.
(b) Using Boolean algebra and PoS (Product of Sums) with the 3rd line of the truth
table we get X = A + B. This circuit requires just 2 logic gates and is drawn as
Question 2.
As there are less rows with an output of 1 we will use SoP (Sum of Products) with
these three rows.
Output= ABC + AB C + ABC
-- -
C(A B +AB +AB)
-- -
C(A B +A(B + B))
C (A B + A(l»)
C(AB+A)
C (B + A)
Which is equivalent to the following circuit diagram.
A ----,
B--V~X
C ---------'-
Question 3.
-
(a) A B C AB X
0 0 0 1 1
0 0 1 1 0
0 1 0 1 1
0 1 1 1 0
1 0 0 1 1
1 0 1 1 0
1 1 0 0 1
1 1 1 0 1
(b) As there are less rows with a 0 output we use PoS (Product of Sums). the rows
have inputs of 001, 011 and 101 which we reverse to fonn our PoS equation.
x = (A+B+C)(A+B+C) (A+B+C)
- - - - -
(A+B+C) (A+ B +C) (A +B+C)
(A+B+C) (O+AB+AC + A B +0+ B C + A C +BC +C)
- - -- -- -- --
(A+B+C) (AB+AC+A B+B C+A C+BC+C)
(A+B+C)(AB+A B+AC+B C+A C+BC+C)
- -- - - -
(A+B+C) (AB+ A B +C (A + B + A +B+l))
- -- -
(A+B+C )(AB+A B +C)
AAB+AA B+AC+BAB+BA B+BC+CAB+C A B+C C
AB+OB+AC+AB+OA+BC+CAB+C A B+C
- - - ----
AB+AB+AC+BC+CAB+C A B+C
- --
AB+C(A+B+AB+A B+l)
AB+C
Which is equivalent to the following circuit design.
Notes
~ In question 1 (a) the C, D and the E, G columns are required for full marks. As
the question indicates the outputs will be the same then these extra inputs are what
shows the processing performed within the circuit.
411 The 6 NAND circuit diagram in question 3 is not as complex as it first looks. A
NAND gate with a single input is logically a NOT gate. In this circuit there are two
places where 2 of these NOT gates follow each other which means they cancel
each other out and can be ignored. This greatly reduces the work to be done
constructing the truth table in part (a).
Oil Question 3 (b) is definitely a difficult problem to solve from the truth table using
Boolean algebra alone. It may have been simpler to attempt to find a solution by
inspecting the truth table. Looking at the C and X columns we can see that X is
pretty much the opposite of C. The only exception is the last row where A, Band C
are 1. Using this observation one could conceivably determine the answer X=
AB+ C directly.
@ Another alternative for question 3 (b) is to write the Boolean equation based on the
original 6 NAND circuit diagram and then simplifY" using Boolean algoebra.
x = ABC
ABC Removing the tvvo sets of double NOTs
AB + C Using 9b (DeMorgan's theorem)
«I To simplifY" writing Boolean expressions using word processors it is common in
some references to use an apostrophe as the symbol for NOT. That is, A' is the
- -- -
same as A, (A+B), is the same as A + Band (AB)' is the same as AB.
SPECIALITY CIRCUITS
There are a number of circuits that are in such common usage they are available
packaged within ICs and are an integral part of modem CPUs. These circuits include
adders, flip-flops and shift registers. In this section, we examine the circuit designs
behind each of these specialty circuits.
Binary adders
Addition of binary digits is a crucial operation for most software products hence it
makes sense to provide standard circuits to carry out this task. Let us examine the
process of designing a circuit to perform 8 bit binary addition.
We commence by considering the truth table required In Jut Output
for the addition of two bits (see Fig 10.59). Ifwe can A B Carry Sum
develop a circuit for two bit addition perhaps we can 0 0 0 0
reproduce our design to extend the solution to 8 bits. 0 1 0 1
1 0 0 1
The carry column in the truth table is identical to an 1 1 1 0
AND gate truth table and the sum column is identical
Fig 10.59
to the XOR truth table. Our circuit design will Truth table for the addition of two bits.
therefore require an AND and an XOR gate. Using
Boolean algebra, Sum= A EB B and Carry = AB. The completed
circuit is shown in Fig 10.60. ~~D-sum
This circuit is great if we just wish to add two bits, however we
wish to extend our addition circuit to add 8 bits. There is a
problem with this circuit, as it does not take account of possible
Lb-carry
Fig 10.60
carries from the previous addition. In fact, this circuit does only Binary halfadder
halfthe job and is therefore called a 'half adder'.
Let us now design a circuit that takes account of a previous carry. This circuit will
need 3 inputs; A, B and Carry In, together with outputs for the Sum and Carry Out. As
there are three inputs to this circuit, our truth table Input Ou:put
will require 23=8 rows (see Fig 10.61). The binary Carry Carry
A B Sum
addition of the inputs results in the outputs shown In Out
in the table. 0 0 0 0 0
0 0 1 0 1
Examining this truth table seems at first glance, to 0 1 0 0 1
indicate that the Carry Out behaves like an AND 0 1 1 1 0
gate when Carry In is 0 and like an OR gate when 1 0 0 0 1
the Carry In is 1. Similarly, the Sum behaves like 1 0 1 1 0
an XOR gate and a NOT(XOR) gate. On further 1 1 0 1 0
1 1 1 1 1
examination, we find that the sum can be obtained
by performing Carry In XOR (A XOR B) and the Fig 10.61
Carry Out is 1 if two or three of the inputs are 1s. Truth table for the addition of two bits
with carry in and carry out.
Comparing these observations with
the half adder circuit indicates we
can use two half adders to create a C¥1Y In -r-----.;.-;.--1~
A
full adder circuit. If either of the
B
half adders produces a carry then
there needs to be an output carry. Carry Out
As a result Carry Out is the result of
an OR gate between the carry Fig 10.62
outputs from the two half adders. Aftll adder combines two halfadders.
Fig 10.62 shows a full adder created
in this way. :'-j~p~t;-': r~tp~i~'1
i Carry : , - - - - - , ! sum :
We now have a circuit that successfully adds two binary Bit 0
{ 1 A;
digits allowing for a carry from a previous addition and .! B =."---.......--;J
sending a carry to the next addition. How can we use : Carry IT' ;:==:::;=t Sum
this circuit to add 8 bits? We need merely to daisy chain
Bitl { !; A
B
these full adders together. The Carry Out from one full : Carry CE==~ Sum
adder becoming the Carry In for the next. Rather than Bit 2 { : A
redraw all the detail of each full adder we can draw it as : B :;'1...--....I:]
The result is obtained from the eight Sum outputs. : B::r:=: :=jJ
i Carry 0:::;:::: Sum
{
Bit 5 : A!
GROUP TASK Activity : B :;'1...-_-'
Draw up a truth table, including intermediate
Sum
steps for the full adder shown in Fig 10.62.
Ensure the circuit works as intended.
(b)
12.
Let us examine the operation ofRS latches in more detail. Firstly, the normal holding
state for both R and Sis o. To alter the latch to store a 1 requires a 1 to be sent to the
set (S) input, similarly a 1 at the reset (R) input will store a 0 in the latch. Notice that
our RS-NAND latch circuit has inverted inputs,
Input Output
when working with this RS latch it is necessary to
invert the Rand S values before calculating the S R Q Q
outputs. Both the RS-NOR and RS-NAND latches -
0 0 LastQ Last Q Hold
have the same resultant truth table (see Fig 10.66).
0 I 0 I Reset
There are still problems with these latches. The first
being how do we control when a latch is allowed to I 0 I 0 Set
change state? We need to control this to allow
I I X X Illegal
synchronisation of multiple latches. This problem is
solved by adding a clock component to our circuit. Fig 10.66
The next section describes this process. Truth table for an RS latch.
Clocking component
Let us work with our RS-NAND latch, although we
could equally have worked with the RS-NOR latch.
When a number of latches are connected together, it is
vital that we can force all latches to change (or not Q
change) at the same time. By connecting a clock to our
circuit, we can achieve this aim. Essentially, a clock is
an extra input that changes state from 0 to 1 then back to Q
o when we wish to make changes to the attached
latches. When the clock input is at 1 then the latch is Fig 10.67
permitted to change state. When the clock input is at 0 Clocked RS-NAND latch circuit.
no change to the latches can occur.
The advantage of having chosen the RS- Input Output
NAND latch rather than the RS-NOR latch is S R CLK Q Q
that the clock circuitry reverses the inputs, -
0 0 1 LastQ Last Q Hold
hence we are now working with a hold state
of 00 (the original RS-NAND latch required 0 I 1 0 1 Reset
inverted inputs, see Fig 10.65). This is
I 0 1 I 0 Set
preferable as 0 really means low or no
voltage, whereas 1 means high voltage. 1 I 1 X X Illegal
Illegal inputs of 11
Let us examine the first problem of illegal inputs of 11. If we examine the truth table
for the clocked RS latch, we see that Sand R values that alter the value stored in the
latch are the inverse of each other. We can insert a not gate between the S input and
the R input and then dispense with the R input
altogether. This is only possible because of the D---I
inclusion of the clock circuitry. The hold Q
conditions now exist only when the clock is O. This CLK-+----I
revised latch design is known as a data latch, D-
type latch or merely a D latch. The D or data input Q
is now the same as the value stored within the latch
and output at Q. Often this circuit is called a D- Fig 10.69
type flip-flop, however this is not strictly correct, D latch circuit. The input at D
is stored and output at Q.
as it has no edge trigger component.
Edge trigger component
An edge trigger circuit is used to ensure the flip-flop only Positive Negative
edge edge
changes state once for each tick (1) of the clock input. The
clock changes state from a 0 to 1 and back to a 0, the aim is to \ I
perform the change of state within the flip-flop as the clock SLrLJLJL
o 1 0 1 0 1 0 1 0
changes state. Each change of state is called an edge, in other Clock ticks )
words the flip-flop is triggered by either an up or positive
Fig 10.70
edge or a down or negative edge. An edge is the point
Edge trigger components are used on all types of flip-flops. where the signal changes.
For this discussion, we will consider the addition of edge
trigger circuits to our D latch developed above. It is possible to design edge trigger
circuits that respond to either the positive or the negative edge of the clock signal. For
our discussion, we will examine a negative edge triggered D-type flip-flop.
._._.-.-._.-.-
,
Q
Q
Datan
Input
Clock
Input
D
-Q
Output
Inverted
CLK -~------I )0-----' Output
:... _. _. _. _._. _._. _. _. _. _._. _. _. _. _._. _. -. -,'
Fig 10.71 Fig 10.72
D-type flip-flop with negative edge trigger or more simply aD flip-flop. Symbol for a D flip-flop.
Edge triggered flip-flops consist of two latch circuits, a master and a slave.
(Sometimes these flip-flops' are called master-slave flip-flops). The inverter
connecting the clock inputs is the key to the edge trigger function. If the clock input is
o then data inputs at D will have no effect on the master latch. Consequently, there
will be no change in the input into the slave latch, hence the stored value and output
remains unchanged. This is precisely what is required when the clock sends a O.
What about when a 1 is sent from the clock? In this case, the data input D into the
master latch becomes active, as a result the value stored in the master latch can be
altered to reflect the input. Whilst this is happening an inverted clock value of 0 has
entered the slave latch, hence the slave latch is disabled and does not accept the input
from the master latch. When the clock falls again to a 0 (the negative edge), the
master latch is again disabled, however the inverted clock input is now 1 so the slave
latch is active. Therefore, the output from the master latch can enter the slave latch
and alter its contents. The result being that both latches are now storing the new data
value D. As with the previous latch designs this value is output at Q.
Inverted
The JK flip-flop is a modification of the RS Flip-flop that uses R
ese!
R Output
a different system to overcome the illegal 11 problem.
DQ
Essentially, the JK flip-flop uses feedback from the outputs to RS Flip-flop
disable the input not being used.
Set Output
Other modified flip-flops have an input that causes the value Clock
stored to be returned to O. This is useful when a large number Input
- Inverted
of flip-flops need to be cleared simultaneously. In the next Reset K Q Output
section, we look at shift registers. The clear function is
JK Flip-flop
particularly useful when flip-flops are to be used as part of
registers within the cpu. Data
D Q Output
Input
Clock
Input
Inverted
GROUP TASK Investigation CLR Q Output
Shift registers
Shift registers are used to store binary data. Registers are nonnally designed to store
data in multiples of 4 bits. All shift registers allow for data to be moved into or out of
the register. Designs are available to shift data left and/or right; these functions are
necessary to perfonn binary mUltiplication and division. A shift of one bit to the right
divides the contents by two; a shift of one bit to the left multiplies by two.
Essentially shift registers are groups of flip-flops connected together in a chain. The
whole group is controlled by a common clock. This means that data can be shifted
simultaneously throughout the register. If a clear function were present on the
component flip-flops, this would also be controlled by a common circuit.
There are a number of ways of connecting flip-flops to provide for particular
requirements. Some common arrangements include: Data
Input
D Q Output
• Serial in - serial out
Clock
• Serial in - parallel out Input
Inverted
• Parallel in - serial out CLR Q Output
For our purposes, we will examine the Serial in - serial out, Parallel in - parallel out
and the Bi-directional shift register. In each case, we will use D flip-flops with clear
inputs, however similar designs could be created using the other common flip-flop
designs. For our discussion we will create four bit register designs but these designs
could easily be extended to any number of bits.
Serial in - serial out shift register
Flip-flop 3 Flip-flop 2 Flip-flop 1 Flip-flop 0
This register is populated Data Data
one bit at a time. To load Input
- D QI - - D QI-- D QI-- D Q I - - Output
4 bits requires 4 clock - t> -
,-- t> -
- t> -
- r> -
ticks. As a bit is input Q Q Q Q
CLR CLR CLR CLR
from the left all other bits I I I
are shifted to the right,
Clock
Clear 1 1 1 I
with the right hand bit Control
Fig 10.75
being lost out of the Serial in - serial out shift register
register.
To load the register with data requires activating Data Flip-flop
the clear control line. This is done by sending a Clock
Input 3 2 1 0
1; this sets all flip-flops to O. The input data is 0 1 0 0 0 0
then supplied to the data input line of flip-flop 3 1 1 0 0 0
one bit at a time. 1 bit enters the register for each 0 1
tick of the clock. A bit destined for the right 1 1 1 0 0
0 0
hand flip-flop (flip-flop 0) must travel through 1 0 1 I 0
all preceding flip-flops to reach its destination. 0 1
Fig 10. 76 is a desk check of this register I I 0 1 1
receiving the bit pattern 1011.
Fig 10.76
Desk check of the serial in - serial out
shift register using the data 1011.
Data
Q Output
The logic of this flip-flop is quite involved and requires intensive examination to
understand completely, Let us examine a left hand shift using this circuit. Firstly, the
left/right control is sent a 0, indicating a left shift This input is reversed by the
inverter on the second left/right control line, As a result, each set of 3 NAND gates,
controlling the inputs into each flip-flop, receives a 1 at the top NAND gate and a 0 at
their bottom NAND gate, Consider the bottom NAND gate preceding each flip-flop,
as it has received a 0 then its output must be a 1 regardless of the value in its other
input, effectively these gates have been disabled. The upper NAND gates, which
received a 1 from the left/right control, are enabled, A 1 from their other input will
result in a 0 output and a 0 results in a 1 output Following the source of the other
input to the upper NAND shows it comes from the output of the flip-flop to the right,
which is correct for a left hand shift The third NAND gate preceding each flip-flop
input effectively reverses the input back to its correct state for storage in the flip-flops,
Of course, all this can only occur ifthe clock has sent a 1 to each flip-flop, Notice that
the right hand flip-flop will gain its new data from the data input line,
Question 1.
Consider the following binary half adder circuit:
A--+""""'D-
B ~>-+-I
Sum
Carry
(a) IdentifY the two logic gates used in the above half adder circuit.
(b) Construct a truth table for the above half adder circuit.
(c) Create a circuit for a full adder.
(d) Explain how a circuit to add two 8-bit binary numbers could be constructed.
Question 2.
Describe the essential feature of flip-flops that allows them to store binary digits.
Suggested solutions
Question 1.
(d) When we add any 2 single bits from a number which has multiple bits, there can
be a carry which needs to be carried forward to be included in the addition of
the next 2 bits in the number. In effect three bits are input and added resulting in
2 bits being output.
This circuit requires that the carry from the previous addition of the lower order
bits in the two 8-bit numbers is carried forward into the addition of the next 2
equivalent bits. As there are 8 pairs of bits then 8 full adders must be connected
together - the carry out from each full adder connecting to the carry in of the
full adder for the next higher significant bits.
Question 2.
The latch component of the flip-flop. This component contains two gates with the
output of each linked back to one of the inputs of the other. This provides feedback to
the gates so that the latch is able to remain in a stable state. There are two possible
states representing the binary digits 0 and 1.
Mouse buttons are simple switches; either they are up or down. The sensors for X and
Y direction detect and send a series of Is and Os to the mouse's Ie. The Ie converts
the signals from the switches and X and Y direction sensors into coded form, which is
sent to the computer via a PS2 serial port.
All data packets are made up of three distinct components; header information, data
and trailer information. The data will often contain control characters used to cause
some predefined action by the hardware e.g. moving a robotic arm or moving a printer
head to the left hand side. Let us consider each of these three components in detail.
Header information
The information preceding the data is known as the header. For communication with
hardware devices within the computer system or connected directly to one of its ports,
the header is often just a single start bit. This bit signals to the receiving device that a
new data packet is commencing.
Data characters
The actual data being sent. This is the stream of data that is used by the receiving
device. Often control characters are included within this data stream. For example, a
modem requires control sequences to activate its internal functions, such as
instructions to go off-hook or dial a number.
Trailer information
The information following the data is known as the trailer. Trailer information
includes error checking bits and stop bits. There are various error checking techniques
that can be used, often a simple parity bit is used. A stop bit is often used to indicate
the end of the data packet.
Processing of the data stream
Once a data stream has been received from a hardware device it will requrre
processing by the computer. The software used to perform this function must be able
to understand the precise format of the data stream. Control characters will need to be
isolated and acted upon and strings of data will need to be interpreted into forms that
can be used by the system. The processing required is dependant on the particular
hardware device.
The PEC20 lOuses the same general format for both STX
messages it sends to the PMS and messages it receives PABXmodel
from the PMS. Each message is comprised entirely of (2 char)
ASCII characters. The header commences with the STX PABX Version
or start of text character, which is followed by two Function code
characters indicating the model of the PABX, in this (2 char)
case, P2, and a single digit indicating the version; for Message length
hotel systems the version is always a 5. Hence the header (3 char)
for all messages within the hotel will be STX P25 which Data
Function sub-code
translates to the ASCII values 2805053.
Following the header information the data to be Data
processed commences. This data commences with a two
character function code, followed by three digits
Checksum
indicating the length of the message in characters, Trailer {
ETX
followed by a function sub-code; a total of six characters.
The message length is the length of the message Fig 10.84
General message format for
including the header but excluding the initial STX the PEC2010 PABX
character and final ETX character.
The trailer information for each message contains a 1 STX
byte checksum followed by the ETX or end of text character 2 P
3 2
which has an ASCII value of 3. After each message has been
sent, the receiver sends an ACK (acknowledge) if the 4 5
5 2
message was received correctly or a NAK (negative 6 4
acknowledge) if an error was detected. If a NAK is received 7 0
then the message is resent. 8 5
9 4
Let us now examine the format for a particular function:
10 4
Guests need to be charged for calls they make according to II
the length of the call and the destination of the call, these 12 Extension
13 number
messages are transmitted from the PABX to the PMS for 14
inclusion on the guest's account. This function is called the 15
'Call Detail' function and is assigned the function code 24. 16 Line number
17
Within this function there are a number of sub-codes to deal 18
Called number
with internal calls, operated assisted calls and normal direct 37 (Space padded)
calls. The function sub-code we require is coded as a 4. Fig 38
10.85 describes the message format of "Call Detail" function 39 Call start time
40
24 sub-code 4. Each character is coded and sent using ASCII 41
(Hours, min,
including the value of the checksum. 42 sec)
43
Let us examine an example message coded using the 44
45
specification described in Fig 10.85. Mr Bloggs in room 305 46 Call duration
makes a call to 0291234567 at 17 minutes and 23 seconds 47 (seconds)
48
after 6pm, the call lasts 256 seconds. In this particular hotel 49
there are no metered pulses and the extension numbers are 50
51
the same as the room numBers. The message sent would be 52 Metered pulses
as follows: [STX] P2 5 24 0544 0305 006 0291234567 [10 53
54
spaces] 181723 000256 00000 [Checksum] [ETX]. When 55 Checksum
converted to ASCII codes, we get the data stream: 2 80 50 53 56 ETX
50 52 48 53 52 52 48 51 48 53 48 48 54 48 50 57 49 50 51
Fig 10.85
52 53 54 55 32 32 32 32 32 32 32 32 32 32 49 56 49 55 50
Call detail message format
514848485053 544848484848 [Checksum] 3. for the PEC2010 PABX
The PMS software must be able to interpret this message. To do this requires a
procedure or function that firstly is able to ensure the message was received correctly
and secondly is able to extract each field from within the data stream. Imagine the
data stream is stored as a string in the variable InStream, Fig 10.86 describes a
possible algorithm for checking the input data stream has been received correctly.
BEGIN Checklnstream(lnStream,OKFlag)
Set OKFlag to False
Set LenStream to length of InStream - 2
Check message {
length is correct
Set MesLength to value of chars 7 to 9 in InStream
IF LenStream = MesLength THEN
Set Checksum to 0
Set CharCount to 2
WHILE CharCount <= MesLength
Ensure Checksum Add ASCII value of character in position Charcount to Checksum
is correct Increment CharCount
ENDWHILE
Set CheckStream to ASCII value of second last char in InStream
Set Checksum to last two digits of hex value of Checksum
IF CheckStream = Checksum THEN
Ifboth length ~ Set OKFlag to True
and checksum ENDIF
are correct ENDIF
END Checklnstream
Fig 10.86
Algorithm to check the length and Checksum of an input message.
For this particular 'Call Detai1' function the PMS software requires the extension
number, called number, time the call was made and the length of the call. The PMS
must also calculate and store the call charge. All this data will eventually be stored in
the guest's account. An algorithm to perform this processing is reproduced below.
BEGIN ProcessCaIiDetail(instream,CaIiRecord)
CaliRecord.Room = Value of chars 11 to 14 of Instream
CaliRecord.Phone = Value of chars 18 to 37 of Instream
CaIiRecord.Start.Hour = Chars 38 to 39 of Instream
CaIiRecord.Start.Min = Chars 40 to 41 of Instream
CaliRecordDuration = Value of chars 44 to 49 of Instream
CaliRecord.Charge = CaIiCharge(CaIiRecord.Phone,CaIiRecordDuration)
END ProcessCaliDetaii
Fig 10.87
Algorithm to extract the call details from the input data stream.
Control systems
A control system is made up of sensors that obtain data from the environment and
actuators that are able to perform output functions under the direction of a controller.
In this course, we are concerned with control systems where the controller is a
computer system. The sensors provide the input into the
system, the controller performs the processing and as a
consequence directs the actuators to perform some - . 'I
physical task. There are two broad categories of control
system; open control systems and closed control systems. •••••
An open control system is not able to react to its
environment. For example, in many hotel rooms the lock •
on each room is activated using a magnetic stripe card. The
card is encoded with details of the guest's arrival and
departure time together with a unique code particular to the
room. A sensor in the lock reads the magnetic stripe. The Fig 10.88
Hotel door locks are examples
details are processed by a controller within the lock. If of open control systems.
they are correct, an actuator unlocks the door. There is no
feedback to the controller, and in this case, none is
required.
A closed loop system is able to react to its environment. In
other words, the sensors provide feedback so that the
controller can cause the actuators to react to changes in the
environment. For example, the antilock braking system on
a car senses when a wheel has locked (stopped turning)
and causes the brake on that wheel to be momentarily
disengaged. The actuators, in this case, are a series of
valves that release hydraulic pressure in the system. A
closed loop exists between the sensors and the actuators.
Production lines that use robots to perform repetitive tasks Fig 10.89
Antilock brake systems are
utilise both open and closed control systems depending on
closed control systems.
the application. Sensors that are able to detect movement,
light and motion provide the input into these systems.
Often the actuators are electric motors that cause movement of portions of the robot.
Robots that are part of a closed system are often called intelligent robots as they able
to react to their environment. Robots that are part of an open system are known as
dumb robots as they will continue to carry out their task regardless of changes in their
environment.
Question 1.
On many major Sydney roads there are electronic messages. The EDI model 2411 is a
particular model of scrolling electronic marquee that is 200rnm high and is able to
accommodate up to 24 characters.
Qu.estion 1.
(a) <CTRL-D><CTRL-G> "000" <CTRL-J> "01" <CTRL-N> <CTRL-O> "HELLO" <CTRL-O>
"WORLD" <CTRL-R>
(b) BEGIN Displaymessages
Index=l
Stream=""
Message=Messages(lndex)
WHILE Message :;f:. "ZZZ"
Stream = stream & <CTRL-D><CTRL-G> "000" <CTRL-J>
Stream = Stream & Integer part of Index /10
Stream = Stream & Remainder of Index /10
stream = Stream & Messages (Index)
Stream = Stream & <CTRL-R>
Index = Index + 1
Message = Messages(lndex)
ENDWHILE
Send stream to displays
END
Message P:rotocol:
<start-of-msg> <addr> <msg no> <text> <end-of-msg>
where
Fig 10.90
Abridged extract from the technical manual for the EDl 2411 scrolling marquee.
Question 2.
A model helicopter is controlled via RF signals from a remote control
transmitter/receiver. Within the remote control all messages are represented and
processed as ASCII characters.
The helicopter has 3 motors, one controls its forward speed, one causes it to rotate
either left or right and another causes it to either climb or dive. A series of commands
can be combined into a single data stream. Each data stream commences with an STX
or start of transmission character (ASCII code 2), followed by the total number of
characters in the command sequence, and then the actual command sequence. After
the commands an ETX or end of transmission character (ASCII code 3) terminates the
data stream.
The motors respond to the following commands sent from the remote control.
Command Description
RO Rotate left
R1 Rotate right
R Stop rotation
AO Altitude up, meaning helicopter will climb.
Ai Altitude down, meaning helicopter will dive.
A Maintain altitude.
Sn Speed where n is an integer from 0 (stop motor) to 9 (full speed)
For example the data stream <STX>6ROA 1S3<ETX> causes the helicopter to rotate left
and dive at a speed of 3.
The helicopter transmits a data stream specifYing its position every second using data
collected from its sensors. There are always 9 characters of data. The first 3 characters
represent the current bearing from 000 to 359 degrees. The second 3 represent the
altitude from 000 to 999 metres. And the final 3 characters represent the distance
travelled in the previous second from 000 to 999 metres. This data is preceded by an
STX character and is terminated with an ETX character. Hence each transmission
received by the remote control is 11 characters long. For example the data stream
<STX>180010020<ETX> means the helicopter is flying due south at a height of 10
metres and travelled 20 metres in the last second.
Wind conditions alter continuously and have a significant effect on the helicopter's
bearing, speed and altitude. As a consequence the three motors need to be constantly
altered in order for the helicopter to maintain steady flight.
My computer teacher