Chapter 1 Data representation
Chapter 1 Data representation
ChapGFil
Data Representation
Chapter Objectives
Introduction
Erample
Convert 2l to binary
I
l'
We write down the
remainders from boftom
upwards to get the answer
l0l0l2
Example
. Therefore, 12 in binary
is I t002
IJ' The ns't stage is to convert the
decimar fraction 0.75 to a binary representation
. Multiply the decimal fracti
by 2' The whole number
to the right ofth. poirrt----on part ofthe result is the
first binr'
.75 x 2 - 1.5, the frst binar
ortr'e point is a r.
so ru,, *" i"u. .z;;;1.'ffiljorf' 'ist"
Next we disregard the
whole nr
b.y.2 olce again. The previous rezult (the I in
,n.,. part of this
this case) and md
right of the
;oint "Tllil*.ofthe
'umDer new resu.lt is the second
bi;*y;-;;
.5 x-2 = 1.9, the second binar,
to.the risht orthe point
so f"r, we h"ve.iif:i#.:'ii['j is a l.
If for example, we are convertinga binary fraction to decimal and we notice that the steps to
be performed are exactly the same actions we had in the previous
steps we are then bound to
have an infinite binary fraction.
In other words, we will never get a 0 as the decimal fraction part ofour result but going to have
a repeating pattern.
For example, 3.1 converted to binary will produce the following repeating pattern:
It .00011001100110011 ... (base 2)
001I is a repeating pattern.
Example
Convert 5.37510 to binary
The next stage is to convert the decimal fraction .375 to a binary representation
1.500 x2 1.000 (l becomes the third value after the binary point)
(fractional part becomes 0, so we stop)
First, write the place values starting from the right to the left hand side, starting from 20 (ifthe
number is an integer)
Write each digit under its place value.
--L
j
. Multiply each digit by its corresponding value.
. Add all the products to get the denary equivalent.
Example
Convert l1 100 to denary
Example
Convert l0l.l I to denary
l0l.ll=l0l+0.11
l0l and 0.1I are converted separately and combined to produce the final answer
as indicated below.
lol =(k22)+(lx2o)
=4+l
=5
Example
Convert l l l l.l 1000 to denary
lt
t
-a
. The following shows the equivalent representation ofan integer binary number and a fractional
binary number
28 27 26 2s 24 23 22 2r 20
256 128 64 32 l6 8 4 ) I
I 0 I 0 o o 0 0 0
I o 0 0 0 0 0 I I I I I o 0
Example
Convert 88r o to octal
Example
Covert 27ro to octal
Example
Convert 23.015625 to octal
-r-
I
lr
?
. Therefore, 23ro is 27t
iii. The next stage is to convert the decimal fraction 0.015625 to an octal representation.
we
perform the same procedure as we did in binary but in this case we multiply
big.
Exarnple
Convert 167r to denary
Power g4 g3 g2 gr go
Equivalent to: 4096 512 64 8 I
Octal Digits I 6 7
(1x82)+1dxa2;+17x8o)
(1x64)+(6x8)+(7xl)
64+48+7=ll9ro
\r
I
t7 =(lx8r)+(7x8o)
=8+7
= l5lo
0.52 = (5x8-r) + (2x8-2)
= 518 + 2/64
= 0.625 + 0.03125
=0.65625
17.528 =15+O.65625
= 15.65625ro
Activity 2
Decimal number 0 I ) 3 4 5 6 7 8 9 l0 ll 12 13 l4 l5
Hexadecimal equivalent 0 I 2 3 4 5 6 7 8 9 A B c D E F
' The same method of dividing the number by its base as used on binary and octal conversions
I
and taking the remainders only also applies on decimal to hexadecimal conversion.
Example
Convert 20510 to hexadecimal
hr
\
i
(
E1
. C represents 12 and E represents 14'
. Therefore, 20610 = CEro
Example
Convert 97.3510 to hexadecimal
. Therefore,9Tro is 5116
Example
Convert Dl ro to denarY
I
. Therefore, Dll6 = 20gro
Example
Convert A7.4D16 to denary
= (Axlor) + (7x16o)
=760+7
= t67ll
0.4D = (4x16-r) + (Dxro-2)
_ = (4xr6_r) + (r3xl6_2)
= 0.25 + 0.0507812s
= 1G7.30078t25rc
l0
convert each group separately to its decimal equivalent, which will automatically be in base
8.
Combine the decimal values obtained to obtain the octal value.
Example
Convert 10001I l0l0l0l2 to octal
(i) Group the bits in 3s starting from right going to the left
00llooo l1l1lo10ltol
22 21 20 222' 20 22 2' 20 22 21 20 22 zr 20
001 000 ll I 010 l0 I
I 0 7 ) 5
Example
Convert 527s into binary
7
l0l, 010, I1l,
(ii) Take the binary digits and join them into one binary number
l0l0l0l1l
ll
. Therefore, 567" = t916161 1r,
Conversion from Binary to Hexadecimal
Example
C.onvert I 1 10001 I l0l0l0l to hexadecimal
(i) Group the bits in 4s starting
from rigii going to the left
olllloooll llollorot
(ii) Convert each group separately to its decimal
equivalent
01f l becomes 5 (in decimal)
I l0l becomes D (13)
0001 becomes I
0l I I becomes 7 (0 has been added
to the left to make them 4 bits)
23 22 21 20 23 22 2'
0l
20 23 22 2L 20 23 22 2r
ll 0001 ll0I
20
7 I
010 I
D (t3) 5
(ii) Combine the values obtained
. 71D56
. Therefore, l l tO00l l l0l0l0 tz = 7tDlta
Conversion from Hexadecimal to
Binarv
. Take each digit separately and
then convert it to binary by dividing
it by 2
' Put each binarv result obt-T:1l""
bil;i';.;;;*d
. Take the binary digits and join 1 0s to the reft to make them
them into one binary number. 4 bits
Example
Convert 5CA16 to binary -ir
(i) Convert each digit separately to
binary
) Decomes 0l0l (append a 0 to the
Ieft to make them 4 bits)
12
f
C becomes I lfi)
A becomes l0l0
c A
01012 il002 l0l0z
(ii) Take the binary digits and join them into one binary
number
0l0l I l00I0l0z
. Therefore,5CAl616
= 0l0l I t00l0l0z
Activity 4
2.
a) :r::y:m number of ca.lculations,' convert
Y:* " 2EF2I6 '--'-"vtv"a
the following numbers
to octal
uzsss
BinarySystem
' using.binary system the data is
represenred in two possibre states,
that is, 0 and I, thus in
' Most computing devices use the
binary number
rystem to represent electronic circuit vortage
state, which considers 0 vottage
input;r;;;; i;il;. input as on.
' The seguence of oNb and or-rt
rJt.t tr,.'.i..*Jlrj""s trat the computer
can under_
. The 0 or I is known as a binary digit.
Nibble
. A nibble is halfa byte which is a group
of4 bits, for example, 0l10.
Byt"
' o a collection of 8 bits, for example,
0r 1000001, A group of 8 bits
l.:n-r represent a charac-
Word
. A word refers to a number ofbits
that a particular processor handles
at once.
l3
' The term word rength or word size is used to
measure the number of bits in each word,
for
example, 16 bits, 32 bits, 64 bits etc.
' Thus' word size affects processor speed as a 64
bit processor can process data faster than a 32
bit processor.
Advantages of Binary System
' It is easier to construct.electric circuits based on only
two binary values 0 and I or oN and oFF
logic rather than construct devices that can understand
forms of natural languages,
nuturl mjua. ar.i" ir,. diferent
' Binary data is arso reasonable simple to store - again
only needing a two state storage (on/off).
' calculations can be carried out using ,""ronubry simpie
active
"ele"-;;;;
circuits), since it only requires on and off(l ana b; sign"ls. ar-i-d" transistor
. All forms ofdata can be represented in binary sysiem format.
' Digital devices are more reliable, sman and uie iess
energy as compared to analogue devices.
' Binary codes are suitable for the computer applications
and digit"i.orrr-o.ri.ltlirrr.
BinaryArithmetic
' Addition, subtraction, multiplication and division can
be performed on binary numbers in a
similar way as we perform the arithmetic operations
on de-nary numbers.
BinaryAddition
' In decimal addition, ifyou add,27 + 3 you get 30; to obtain the answer 30, the procedure is as
follows:
Example
l00l0l + l0l0l
t4
Explanation
l00l0l
+l0l0l
lll0l0
6rst column (from the right!) I+1=0carryI
second column : 0+0+ I (carried) = t
third column : I + I + no carry = 0 carry I
fourth column : 0+0+1(carried)=l
fifth column : 0+l+nocarry=I
sixtl column : l+0+nocarry=l
ll I ll {- Carry
l0 tll
+ I l0l0l
l00rr00
Example
Find the sum of the binary numbers 10001 and I I l0l
I I €-Carry
10001
+ I l10l
r0lrlo
Binary Subtraction
. |ust like in decimal subtraction, ifyou must subtract a one from a zero, you need to "borrow"
from the left.
Example
l0ll0ll - 10010 = l00l00l:
l0l l0l I
- 10010
l00l00l
Example
t0l0l l0 - t0l0l0
l5
00
+to+t 0110
- l0 l0l0
l0 lt00
Binary Multiplication
' Binary multiplication is actually much simpler to calculate
than decimal multiplication.
' In the case of decimar multiplication, we need to remember
4 x 9 = 36,7 x7 = 49, and so on.
' In binary mu.ltiprication, we only need to remember
the following:
0x0=0
0xt=0
lx0=0
lxl=l
Example
Multiply l0l by I I
1l0l
x ll
E:qplanation
First we multiply I l0l by l, which produces ll0l.
Then we put a 0 as a placeholder as we would in
decimal multiplication, and multiply I l0l by l, which
produces I l0l.
ll0l
ll0I
I l0 I 0 The 0 is the placeholder
Example t
il
Multiply l0l1.0t by l.t
l0l l.0l
l01l0l
l0ll0l0
I0000.1 I I
l6
I
I
' We multiply the binary numbers as we do in decimal. On the result we then
count the number
of digits after the binary point in the two binary numbers.
' In our example the first number has two digits after the binary point and the second
number
has one digit after the binary point.
. Therefore, the final result will have three digits after the binary point.
Activity 5
Find the product of the following binary numbers
(i) I0I and 10
(ii) 1100 and tI
(iii) t01I.0l anil 110.1
Binary Division
. Binary division involves knowledge of binary multiplication.
Example
l0l l divided by 11.
R10
0 +_remainder,R
OR
l01l divided by I l.
11 )11
I 1.0
tli)'tit
t01 I
-1tll
1
too
10
-11
ilitl
IJJII
1(
-11 I I
100
+ 0
' To get a fractional value, add a binary point immediately to the right of the fourth bit from
the
left and append a 0 bit. Bring down the 0 bit.
' In the above example, the binary fraction repeating is l0 and it will continue. So itt better to
stop at four or six fractional bit places and settle for I l.l0l0 orl l.l0l0l0
l0ll /II = Il R l0 1\
To check our answet we 6rst multiply our divisor I I by our quotient I l. Then we add its' product to i
the remainder 10, and compare it to our dividend of l0l l.
t7
l1
xl I
ll
+ll
l00l +-product of ll and ll
l00r
+ l0
I 0 I I <- sum ofproduct and remainder
Example
l0l I I divided by l0
10'l
1o\l oT1
=rcil
11
-10
1
Example
l0.l I I divided by 0.10
Step I
Remove the binary point from the divisor by moving it two steps to the right.
0,10 becomes OIO
Step 2
We must also move the binary point same nurnber of steps to the right as we did
on the divisor. Re-
member to add 0 bits as needed to fi.ll the new spaces.
l0.lI I becomes l0l l.l
Step 3
Discard/ignore the leading zeros on the dMsor. Then continue with the division
using the two binary
numbers as follows:
l0ll.l / l0
-10
11
-'t0
ll
-10
10
-i0
l8
Activity 6
Octal Arithmetic
. The addition and subtraction of octal numbers follows the same rules as the addition and
subtraction of numbers in any other number system.
. The only difference is in the borrowed number. In the decimal system, you borrow a group of
In the binary system, you borrow
1010. a group of2ro. In the octal system you boirow a group
of8ro.
Octal Addition
Example
16s + 5s
I Carry
t6
+5 --
23
Example
256s + 2239
ll <- carry
256
+223
501
Octal Subtraction
Example
356s -273s
l9
lE Borrcw
,!s 6
_273 ---
63
Example
654s - l36s
g €_ Borrow
6as 4
_l 36
516
Hexadecimal Arithmetic
' The addition and subtraction of hexadecimal
numbers also follows the same rules
as thc
addition and subtraction of numbers in any
. nr_Uer system.
The only difference is in the borrowed "ii.,I" fro"a..i_"i-.yrt"^,
nu_U.L you borrow a grorry
of l6ro.
Uses of Hexadecimal
Hexadecimal Addition
Decimal number 0 I ) t 4 5 6 7 8 9 l0 ll t2
uexadecimal equivalent l3 T4 15
0 I 2 J 4 5 6 7 8 9 A B C D E F
Exarnple
i
4C66+ 28216
I
I ( Carry
4C6
+2 B 2
778 qtl
20
,
-
t
-
..-
Eramplc
4C66 + 28.26
I +- Carry
4C6
+282
778
Hexadecimal Subtraction
Example
35616 -27316
16 ts- Carry
_2 7 3
"56
E3
Example
3A5re -l82re
'i A5
.LB2
lF3
Hexadecimal Multiplication
Example
4A* C2
4 A
c 2
3 7 8 0
+ 9 4
3 8 I 4
Hexadecirnal Division
2t
Example
7s94lA
-6E
79
-78
14
-14
00
Activity 7
Work out the follon'ing:
(i) SBtc t 25rc
(ii) 127rc + SCta
(iii) 4EErc / /4rc
(iv1 BBhc - 6Dtc
(v) 67a + 25s
(vi) 124e / 27a
(vii) 5l4s * 27e
Integer Representation
1f
I
Sign and Megnitude
Example
Ui r, find the range of numbers that can be represented using sign and
magnitude
U.i,,,i
-(27 -t)to+(27-t)
(-t27) to (+128-t)
-127 to +127
Example
Using S-bits rePresent 15 in sign and magnitude
Sign bit: 0
Magnitude: 0001I I I
Example
Using 8-bits represent ,0 in sign and magnitude .'\
Signbit: I
Magnitude: 0010100
23
. Therefore, -20 in sign and magpitude using and g-bits
is l00l0l00
Representation of zero (0) using sign and magnitude
'
zero (0) is set for a positive number o. poriti.rr.
zero and one (l) is set for a negative number
or negative zero.
' using sign and magnitude zero (0) has two representations;
10000000(-0) and 00000000(+0).
' since -0 and +0 are both just.O, it is very strange to
have two air.t *'r.p*r.n"tations for the
same number. This is one of the reasons that
a iimpre sign uit i, p.".ti*.
""i...J'i"
It Complement
. lt complement can be used to represent both positive and
negative numbers.
. Positive numbers do not change and they are iepresented as usual.
' If a'umber is negative *. .un ..p..rent it using onet complement by applying the bitwise
NOT to the number.
' Bitwise Nor is an oPeration on only one operand
that performs logical negation on each bit.
For example, the bitwise Not of l0l0z is 0l0lz
. Simply, in one's complement,0s are negated to ls
while ls are negated to 0s.
' The range ofnumbers that can be reprJsented in
rt complementis found iy the formula:
- (2'"-t-l) to + (2*-t-t)
where m is the number of bits to represent the number
Example
using 4-bits, find the range.rf numbers that can be represented
using ls complement.
- (2n-r- t) to + (2''-r-t) m = 4
- (23-L) to + (23-t)
- (8-l) to + (8-l)
-7 to +7
Example
Using 8-bits represent (i) - t0 and (ii) _2 (iii) +7 in lt complement
(0 +10 = 000010102
-10 = II l10l0lz
(ii) +2 = 000000102
-2 = llllll0lz
t,
\z'
I
(iii) +7= 0000lllz
-7 = ltll000z
+0 = 000000002
-0= llllll llz
Addition in I's ComPlement
. Addition is periormed by doing the simple binary addition of the two numbers.
Example
Using 8 bits, find the sum of 4 and 3
4 00000100
+3 00000011
7 00000111
Exarnple
Using a bits, find 8 - 4 in onet comPlement
8
00001002
+ (-4\ 111110112
[1] 000000112
L--42
2's Complement
. numbers in
Modern computers use two's complement to represent positive and negative
binary.
.Theusefulpartoftwo'scomplementisthatitautomaticallyincludesthesignbit.
25
Advantages of 2s Complement
. Two's complement allows a computer to add and subtract numbers using the same operations
without a need for circuitries to examine the sign of an operand (no need to implement adders
and subtractors),
. Zero has only a single representation, unlike in ones'-complement where it has two values
I1lIlllI (-0) and 00000000 (+0).
Twos complement enables higher precision arithmetic to be handled.
Example
Using 4 bits represent 7 in 2's complement
7=LLI
. Therefore, T =0ILLz
Example
Using 8 bits represent 9 in 2t complement
9= l00lz
. Therefore,9 = 00001001u
26
\
\t'
a
Method I
(i) convert the magnitude of the denary number to its binary equivalent,
if it is not in
binary.
(ii) Append the appropriate number ofzeros to the left
(iit change the binary number to onet complement by changing the 0s to ls and ls to 0s
(iv) Add I to the result
Method 2
i' Convert the magnitude of the denary number to its binary equivalent, if it is not in binary.
ii. Append the appropriate number of zeros to the left
iii. Write all leading 0 bits starting from the right hand side as they are, including the first I bit.
Ifthere are no leading zeros, write the first I bit as it is.
iv. Thereafter change ls to 0s and 0s to ls to get the 2's complement of the number.
Example
Using 4 bits represent (i) -7 and (ii) -3 in two's complement
(i)
+7 0lll2
ls complement 10002
Add I +l
10012
-7= l00l z
(ii)
+3 001lz
Using method 2, write the first I from the right, thereafter, change the second I to
0 and the two 0s
to ls
-3= I l0lz
Addition in 2s Complement
' Addition is pertbrmed by doing the simple binary addition of the two numbers.
Example
(a) Using 5- bits, find the sum of9 and 5
9 010012
+5 00l0la
t4 0l1l0z
(c) Using 5- bits, find the sum of l0 and 7
l0 010102
+7 001 112
l7 10001z
Note. that the binary addition result is a negative number (-15), yet we have
added two positive
numbers, therefore, an overflow error has occurred
Example
Using 8 birs, find 25 - 29
Example \r
Using4bits,find6-6
This is the same as 6 + (-6)
6 01102
+( -6) 1010e
0 ll100002
Overflow bit is thrown away to give answer as 0000 which is 0
Example
Using 4 bits, 6nd -63-94
This is the same as -63 + (-94). Therefore, convert -63 artd -94 into 2's complement and add the two
numbers.
(-63) ll00000lz
+(-94) t0I000l0e
lll 011000112
. Throw away the carry bit 1, to get the final answer as 0110001 l.
. The extra bit I indicates an overflow.
. The result above indicates an overflow as the result of adding two negative numbers cannot
give a positive answer.
(i) Complement the binary number (Convert zeros to ones and ones to zeros)
(ii) Add one to the binarY number
(iiil Convert binary number to decimal
(iv) Prefix a minus sign
OR
(i) Subtract I from the binary number
(ii) Invert all the digits (Convert zeros to ones and ones to zeros)
(iii) Convert the resulting binary number to decimal
(iv) Prefix a minus sign
Example
Convert the 2s complement binary number 010000012 to denary
it starts with a zero (0).
The number is positive because
29
27 26 2s 24 23 22 2r 20
1286432 16842 I
0100000 I
=64+1
=65
Example
Convert the 2s complement binary number I I 1000102 to denary.
Method I
The number is negative because it starts with a one (l).
I I100010
Complement the number 0001t l0l
Add I +l
0001I I l0
Method 2
Subtract I from lll000l0 I I100001
Complement the number 0001 I I l0
Convert the binary to decimal 30
Prefix a minus sign -30
Method 3
Use of weights
-r -30
Range of numbers represented in 2,s Complement
' With two's complement representation there is no bit allocated as the sign bit
but the left-mocr
bit behaves like one.
' unsigred range refers to how many numbers you can represent if you only allow positir
30
numbers.
. Sg*a range refers to how many numbers you can rePresent if you require both positive and
negative numbers.
. Therefore, twot complement range is a signed range since
it represents both positive and
negative numbers.
Foi example, the range ofnumbers that can be represented in an
8-bit register:
xior unsignei numbers will be from 00000000 (0) to llllllll
(255)'
(- to 0l 1l I I I I ( 127).
xFor signJd twot complement range is from 10000000 128)
that can
fh" following iormulae can be used to find the largest number and smallest number
be represented in 2t comPlement:
- (2m-r) to + (2m-r-l)
*ir.r.rrr is the number of bits used to represent the number
Example
using 2's complement
fina ifr" h.g"rt number that can be represented in an 8-bit register
- 12m-r) to + (2m-r-1;
- (288-r-t) to + (28-1-l)
-(27) to + (27 -t)
-L28 to + L27
Activity I
1. Usiig S bits reptaent the decimal number -28 in
(a) Sign anil magnitude
(b) 7's comPlement
(c) 2's comPlement
can be representeil in
Z, Wi"g e Uii *rnPute the llrgest and smallat numbers that
( a) sign an il magnitu ile
(b)l's comPlement
(c)2's comPlement
3 , IJsing 8 bits pnfotm the following calculations using
(a)l's comPlement
(b)2's comPlement
(, 28+2
(ii) 14-8
(iii) -2t-8
3l
Fired Point Arithmetic
Example
using an 8-bit register, find the range
ofnumbers that can be represented
-2m-r to 2m-r_l
32
_2E- l to 28-l-l
-27 to 27 -l
-128 to + 127
. The binary point is fixed at one Position and therefore does not move'
. Given one byte to hold each number, and assuming that there are 7 bits after the imaginary
binary, the fractional binary number may be shown as below
BinarY Point
using an 8-bit register with the imaginary binary point 6xed after the sign bit, one can calculate the
maxiinum positiie number, minimum positive number, smallest negative number and the largest
negative number as shown below.
0 I I I I I I I
0 0 0 0 0 0 0 I
| *2-7
0.0078125
33
Smallest Magnitude Negative Number
r *ro
= -l
. Remember that 2t complement negative numbers start with a I and positive numbers start
with a 0.
The imaginary binary point can be fixed on a stated position. The following is an example
ofan 8-bit
6xed point fractionai binary number with an imaginary binary point after the fifth digit
10001001
l
I
I
Imaginary fixed binarY Point
Example
convert the
Uslng in 8-bit byte to hold each number, with the binary point fixed after the fourth digit,
decimal number 7.5 to binarY.
7 = 0lll
0.5 = 0.1
=01 I 1.1000 (Three trailing 0s are added to make it one byte)
Example
\r
Assuming 3 bits after the imaginary binary point, convert the binary number 000001l0l I
to decimal.
34
I
000001101I
A
I
I
Imaginary fixed binarY Point
000001LOl I
26 25 24 23 22 2r 20 .2r 22 23
Example
Represint -7.25rcin 8-bit binary with the binary point after the fourth digit'
nint: With a negative number we have to apply two's complement always'
23 22 2r 20
,' -l
2-2 2-t 2-1
Step-l
Cal-date the positive equivalent number in binary'
Step-2
Change 0s to ls
and ls to 0s (Complement). I
Step-3
Add I to the result. t
.l0ll-
Advantages of the Fixed Point Binary System
35
Floating Point Arithmetic
' The term floating point is derived from the fact that there is no
fixed number of digits before
and after-the binary point; that is, the binary point can be placed anywhere (float)
relative to
the signifcant digits of the number.
. Floating point numbers are represented using 2t complement
. Floating point representation can handle a wide range ofnumbers, for example, a fixed-point
rePresentation with a uniform decimal point placement convention can repreient
the numbers
123.45, 1234.56, 12345.67, etc, whereas a floating-point representatio; could
in addition
represent 1.2345 67, 123456.7, 0.0000 1234567, I 234562000000000, etc.
.' The structure of a floating point number is shown in the following diagram
The floating point rePresentation ofa number has two parts namely mantissa and
exponent.
Point
bl/ I
0 1 1 0 1 1 6 0 0 0 0 0 0 1 c
l. 7.23 x t02
2. 72.3x l0r
3. 723 x l}o
4. 0.723 x 103
5. 723O x l}'r
36
\ lr
t\ y''
e
. and the exponent 3' The exponent 3 means
This means we need only store the mantissa 0'723
places to the right'
we move the decimal point of the mantissa three
Mantissa / ExPonent
.Using8bitsforthemantissaand4bitsfortheexponentthebinarynumber0'0001lllcanbe
represented as follows:
(i) 0'0001111 x 20
00001111 0000 (Mantissa: 000011l l ExPonent:0000)
(iii) 0.0lltl00x2-2
00111100 1ll0
Notethatifthebinarypointtpositionisnotshowninthemantissa,itimpliesthatitispositioned
between the two left most bits.
as shown above'
in noutirrg point, a number can have dilferent representations
zs 24
.3
z. .2 tl 20 . 2'r 2-2
37
I
Move the binary point 5 steps to the left to ga the following:
l.l00l0l I
To get our decimal point back to where it started, we need to move 5 places to the right. Therefore, 5
Example
A number is represented as an 8 bit floating point number. 5-bits are used as the mantissa and 3- bits
are used as the exponent. Both the mantissa and the exponent are in two's complement.
Show the following floating point in its denary equivalent:
a) 0llll0ll
b) 11000 110
a) 0llll0lr
0llll0I1
Mantissa: 0l I I I (0 means its positive)
Exponent: 01 I (0 means its positive)
The exponent is 011 (3 in denary)
Therefore, move three steps to the right to get the original binary number
0llll becomes lll.l
Convert I I l.l to denary
22 2r zo 2r
421 0.5
lll I
11I.1
=4+2+l+0.5 c.i
38
b) rloo0 lro
11000 I l0
Mantissa: I 1000 ( I means its negative)
Exponent: ll0 (1 means its negative)
since it is negative
Perform 2's complement on the mantissa
11000 becomes 01000
get the original binary
The exponent is 110 (-2 in <Ienary)'
Therefore' move 2 steps to the Ieft to
number
01000 becomes 00010
=0+0+0+0.125
= 0.125
is negative)
= -0.125 (Since the mantissa
39
2' work out the binary foating point for the denary number 97, using ro bits
for the mantissa s
6 bits for the exponent.
' Normalisation is the process of moving the binary point on the mantissa so that the 6rst digr
after the point is a significant digit. This is done to simplifr operations and expressing numbc:
in standard form.
. The binary point is always between the Sign bit and the Most significant Bit (MsB).
Bianary Point
Sign Bit
Mantisa Exponent
. ----------{
For a floating point binary number to be normalised, the first two bits of the mantissa mu$ h
diferent. That is:
1.0 or 0.1 and definitely NOT l.l or 0.0
. T5, if the mantissa is positive, the Sign Bit is always 0 and the MSB is always I (0.1).
. If the mantissa is negative, the Sign Bit is always I and the MSB is always O(i.0).
. For a negative number, there must be No leading ls to the left of the MSB, except the sign
r.uooilrx
. For a positive number, there must be No leading 0s to the left of the MSB, except the sign b3L
o.oroilux
' With positive numbers, the binary point in the mantissa is always placed immediately befolr
the first non-zero digit because it allows us to use the maximum number of digits.
Zero cannot be represented in normalised form. This is because 0.0000000 th; first two digit3
are the same.
A normalised value must have the first two bits of the mantissa different. Usually, the computcr
uses the smallest positive number to represent zero.
To maximise the precision of a positive number you should have a mantissa with no leading
zeros.
40
leading
. number you should have a mantissa with no
To maximise the precision of a negative
ones.
Example
floating point binary number'
iio#t, rfr. denary number 39'75 as a normalised
.- I rz )-3
27 26 2s 24 zt 22 21 20
and
floating point number using 8-bits mantissa
:ffi.[. decimal fraction _5.25 to normalised
4-bits exPonent.
the negative sign to get the following:
convert the fraction -5.25 to binary ignoring
22 2r 20 2-r 2-2
J I 0.5 0.25
4
I 0 I 0 I
t0l.0l
the left
Move the binary Point 3 stePs to
Theexponentbecomes00ll(3indenarysincethebinarypointmustmove3stepstotherighttoget
back to the original value)
convert 0'1010100 to twos complement
Since the number is a negative one
1'0101100
Example
0'010000000 | 000011
Normalise the following floating point number
!
4l
Convert the exponent to denary.
The exponent is positive.
000011 is 310
So it becomes 0.100000000 x 23 - 1
_ _0ooo0r)
0.100000000 x 23 r(oooor r
0.100000000 x 22(oooolo)
0.100000000 | 000010
Or
0.010000000 | 000011 = 0.100000000 000010 (00001t _
| 000001)
- I is to compensate for the
movement of the binary point orr" piu." to tfr" t"n
Therefore, 0.100000000 000010 is the
| normalised floating point number.
Example
Normalise the following floating point number
l.l10000000 | I I I I l0
r.000000000 llllto0
Therefore, 1.000000000 I I I 100 is the normalised
\,
| floating point number.
42
normalise the binary number
3:il1[., ar.he mantissa and 5 bits for the exponent'
0.000101011
o.lllolll x 23(ooror)
11 l0l I I 00101 in normalised form'
Therefore, 0l I 101'l I becomes 0l
to Denary
lt"""t,i"g. Normalised Floating Point Number
ExamPle
number to decimal
Convert the following normalised
010000 ll00
Mantissa: 0I 0000
ExPonent: 1100
exponent is negative
The mantissa is positive and the
(4)
exPonent so that it becomes 0100
Convert the negative 2's complement
-4
Since it is a negative it becomes
43
€ -J.f..idEEl
20 2-r 2-2 2-3 2-4 2-s
I 0.5 0.25 0.125 0.062s 0.03125
0 00001
Therefore, 010000 I100 = 0.03125 in denarv
Example
Convert the following normalised floating
point number to decimal
l0ll000 ul0
Mantissa: l0r 1000
Exponent: lll0
The mantissa is negative and the exponent
is negative
Advantages of Normalisation
' Ensures that a single representation
ofa number is maintained (standardisation).
' Ensures maximum possible accuracy
ismaintai;;; a given number of bits.
. S_*: space by using the space given in an
efficient wav.
. Can be used to detect er.o, .orrdition.
,u.h u, urrd..fl'or and overflow
' Tries to maximise the range ofnumbers
th"t.- t;t.pr;sented in a fixed point representation
(range and accuracy is limited
in fixed point ,.pr.r*iJor1.
Roughly Normalised
t
-v€ converston
_0.1000001 x 2-,rr
45
l<+
' This represents 0.1000000 x 2 rooooooo - 0.1000000 x 2-l2s which is very close to zero;
in fact, it is 2-12e.
Furtherrnore:
' The smallest negative number (i.e. the negative number furthest
from zero) is I.0000000 x
2orrrllrr = -1.0000000 x 2r27 -2127 . -
Activity l0
I' using t0-bit mantissa and a 6-bit exponent, normalise the
following numbers:
(a) 0 0000{1100 (nlrn
(b) 1101110010 0(n011
2' what is the decimal value for the following binary pattens if the
first g bits is the orrtissa
and the last 4 bits are the e*ponent?
(a) 1o1il100 il10
(b) 0to1 woo trco
3, using lo'bit mantbso anil 6-bit e4,oner.t, represent the
folhwing decimal numbers using
n or m ali s e d fl o ati ng point r epres ent ation :
(a) 2s.27s
(b) -8.5
(c) 143
Round-OffErrors
' Rounding is expressing a number to the nearest whole/decimal/binary number.
For exam-
ple' 3.9569 rounded to 3 decimal places is 3.957.If rounded to
the nearest whole numbet it
becomes 4.
' often
-we
cannot represent a denary fraction exactly even if we allow many bits in
memory.
Therefore, the number stored is "rounded off" to the closest possible
binary equivalent.
' In rounding, the least significant bit may be increased depending on digits
removed. The
result should represent the value that is nearest to the original viue.
Foi example,
100.1 = 100 (Rounded_offto 2 significant 6gures)
ll0Il = 11000
(Rounded-offto 2 significant figures) \
ll.l0l = 100 (Rounded-offto 2 significant 6gures)
46
l10l = lll0 (Rounded-off to 3 signifi cant fgures)
. When rounding off, guard against changing the value of the number to become less than it
was before.
Truncation Errors
. Truncation is shortening by cutting offsome characters abruptly at a certain point.
. For example, 3.9569 truncated to 3 decimal places become 3.956. If truncated to the nearest
whole number, it becomes 3.
. Truncation error is the difference between a truncated value and the actual value. A truncated
quantity is represented by a numeral with a fixed number of allowed digits, with any excess
digits'thopped off"
. Often, in either floating or fixed point systems, results are calculated with too many places of
accuracy to be represented.
. We get this type of error when trailing bits are truncated to fit the result in the memory location
available.
. Truncation works as follows:
100.1 = 100 (Truncated to 2 significant figures)
l0l0l= 10000 (Truncated to 2 signifrcant figures)
ll0ll= 11000 (Truncated to 2 significant figures)
ll.l01 ll
= (Truncated to 2 significant figures)
a. Overflow
Overflow occurs when a calculation produces a result that is greater in magnitude than that
which a given register or storage location can store.
. In other words, the result is greater than the number ofbits available to represent the result
value,
. Overflow occurs when a number is divided by a small number or when two large numbers are
multiplied together.
Detecting Overflow
(i) The sum of two numbers with the sign bits of produces a result number with the sign bit on.
4 0100
4 + 0100
8 1000 (Overflow has occurred because 8 is out ofrange)
. Using 4 bits, the range of numbers to be rePr€sented is 1000 (-8) to0lll (+7)
(ii) The sum of two numbers with the sign bits on produces a result number with the sign bit off.
Example, using 5 bits
. 8 0lm0
+8 + 01000
15 10000 (Overflow has occurred because the result now represents a nega-
tive number -16 (10000))
'
If you are doing twob complement (signed) arithmetic, overflow occurs when;
Suppose x and yboth have sign bits with value l. That means both represent negative
lt] numbers.
Ifthe sum has sign bit 0, then the result ofadding two negative numbers hasiesulted iria non,negative
result, which is clearly wrong.
(ii) Suppose x and y both have sign bits with value 0. That means both represent non-negative
.
numbers. If the sum has sign bit l, then the result ofadding two non-negative numbers has resulted
in a negative result.
'However, when a negative and a positive number are added together, overflow cannot occur
because the sum is between the two numbers.
'If you are doing two's complement (signed) arithmetic, overflow flag ON means ihe answer is
wrong.
'Ifyou are doing unsigned arithmetic, the overflow flag means nothing and should be ignored.
b. Underflow
' Underflow occurs where the result ofa calculation is ofvery smaller value (close to zero) than
the smallest value that the computer can actually represent in memory.
' Underflow occurs when a small number is divided by a large number or when small numbers
are multipted together.
Activity 11
Perfurml calculation on the follo*ing signed binary numhers and indicate whether they produced
an overJlow or not:
i) |OOO + 1000
ii) 0l(N + 0(NI
iii) 0rI0 + ilnr
iv) 0000 + (n01
v) 1100 + 1100
Actual error
' Actual error or absolute erroris the difference between the exact/actual value and the computed
value.
. Actual error is obtained by the following formulae:
48
Example
2/3 is approximated to 0.666. Find the actual error and relative error.
l. Actual error
2. Relative error
Relative error = Actual error/Exact value
= (2t3000) | (2t3)
-- 213000 x312
= 0.001
Character Set
. A character set refers to all the characters that a computer system can recognise, which often
equates to characters on the keyboard.
. The characters within a character set can be letters of the alphabet, numbers or symbols.
. Each character is represented by a number, for example, the ASCII character set uses numbers
0through 127 to represent all English characters and special symbols.
. The following are examples ofcharacter sets used by general computers to represent characters:
* American Standard Code for Information Interchange (ASCII)
* Unicode 1
a) ASCII-7
ASCII-7 is a 7-bit standard ASCII code.
The first 3 bits are the zone bits and the next 4 bits are for the character.
ASCII-7 allows 128 characters to be represented, that is,27= 128 combinations'
b) ASCII-8
Manufacturers have added an eight bit to the ASCII-7.
.A,SCII-8 allows 255 characters to be rePresented, that is,28 = 256 combinations.
ASCII-8 has 4 bits for zone and 4 bits for the character.
49
ASCII Character Set
. Codes 0 to 3land 127 represent non printable control characters.
. Codes 48 to 57 stand for numeric values 0-9.
. Codes 65 to 90 stand for uppercase letters A-2.
. Codes 97 to I22 stand for lowercase letters a-2.
. Codes L28 to 255 are the extended ASCII codes.
. The space character is the 33rd value, followed by punctuations, digits, uppercase characters
and lowercase characters.
. It is imPortant to note that digit characters have code values that differ from their numeric
equivalents: the code value of '0' is 48, that of 'l'is 49, that of '2' is 50, and so forth.
. For example, 32 is the ASCII code for a space. So the binary value for a space is 0100000 (i.e.
32 converted to binary).
. The word Five in ASCII is represented as 006 105 lr8 l0l since 006 representsF, 105
represents i, I l8 represents v and l0l represents e. This will translate to 00000110 0t l0l00l
0l110110 0l100101 in binary.
. It is imPortant to note that "l20" is treated as 3 characters in ASCII, which is diferent to the
number 358.
r\r
50
ISCII Ctarl'cter ISGII Gtr:lcta IS{III Chr.rectc
vrlu3 veluc vrlue
000 -! olt:t + 086 Y
001
.E
o4 ol,it t
002 048 088 I
003 046 08e Y
004
.E
o47 I 090 z
006 044 0 091 T
006 o49 t ocz \
007 060 2 o05
008 .H 051 s 09+ l
@0 .I 052 4 095
010 05:i 6 006
011 0t4 6 O'T I
072 o5E 7 094 b
013 056 s 00e c
014 O57 I 100 d
016 164 101 I
016 .P 069 i 102 f
017 'e 060 105 E
018 061 : 10,4 t
019 osz > 105 i
m0 063 ? 106 j
ut7 -u o6+ o 707 L,
.Y
utz 066 I 109 l-
023 -9 0e6 E 109 !
o24 .I ott c 110 ! l
vza o72 s
ut0 :l 0?3 I
118
110
I
t
031 o74 J 777 u
032 I+ecal 076 I 113 Y
0t I 076 T, 119 I
034 o77 t{ 720 r
036 I 078 I 727 I
ogs t 07/, 0 722 z
037 t oso P 123 t
oit8 t oa1 e 724 I
099 08il B 726
040 ( ost s 126 \
041 ) ogt T 727 IIEL
&2 l oa5 u
5l
BCD is used by digital voltmeters, frequency converters and digital clock" to display outpu:
information in decimal.
In BCD, each decimal digit is simply changed into a four-bit binary number ' hich are ther
placed one after another in order.
The following shows decimal digits in BCD:
0 0000
I 0001
7 0010
3 001I
4 0100
5 0101
6 0ll0
7 0lll
8 1000
9 1001
The first wrong and 1010 does not exist in BCD. The error is caused by the range ofnumbers
digit, I is
However, the \
used for representing data in BCD. BCD uses 4 bits which is 2a = 16 combinations.
than 9 then 5 has
,rroi^o^ r"rrg. of riumbers that can be represented is 9. If the sum of bit is greater
(0110) gives us 0010 00002'
to be added tolhe result. Thus adding the result above,0001 10102 to 6
which is 20 in BCD.
52
I
Unicode
. Unicode is enough to represent around 120,000 diferent characters in any language, English'
Chinese and even hieroglyphics.
. Unicode is a universal character encoding standard for the rePresentation ofletters, numbers
and symbols.
. Unicode uses 8 bits, 16 bits, 24 bits or 32 bits to represent a character.
. Each character is assigned a unique numeric value tlat applies across different platforms and
Programs.
. The most widely used Unicode encoding schemes are called UTF-8, UTF-16, and UTF-32.
. LrTF-16 is a variable length which uses 16 bits or 32 bits whereas UTF-32 is a fixed lengh
which uses 32 bits.
. UTF-8 is commonly used and it is a variable length as it contains either 8, 76,24 or 32 bits for
a character.
. UTF-8 characters with a lower Unicode number require fewer bits for their rePresentation
than those with a higher Unicode number.
. Using UTF-8, the character 2 has a decimal value 50 and bin'ary rePresentation of00ll00l0
wherias the Chinese character is represented by a Unicode number 35987 which translates
to I I101000 l0l10010 10010011 in binary.
. Most Microsoft Software and Linux distributions use Unicode.
53
Disadvantages of using UNICODE
Representation
1:.
(i) Data.
the following in ASCII:
(ii) Abyte.
54
Revision
6.Thesumof2.3gandl.4gSistobeworkedusingonly3significantfigures.Findtheactualerror
and relative error iftruncation is used'
t6l
1l'a)outlinetwoadvantagesofrepresentingnumbersin2scomplementoverlscomplement.t?l
subtract 00ll0z from l01l 12 using
b) Assuming that we are working with signed five-bit numbers'
the twot comPlement rePresentation. l2i
to
.i errrr_irrg signed twot complement representation, find the decimal value corresponding
"
0lll0z and 101102.. I2l
represented in
12. a) Using a single byte for each answer, explain how the denary number -29 can be
binary in
(i)
sign and magnitude
(iii)
I's comPlement
(ii) 2's comPlement t5l
t4l
b) (i) Convert -54 and - 104 into 2's complement' 8 bit' binary numbers'
(ii) Add the binary values obtained in bXi) together' l2l
(iii) Co--.t t on the result that you obtained in bXii)' l2l
13.Floating-pointnumbersinaparticularcomputersystem'arestoredusing12bits.Thefirst5bitsare
set of 6 bits is used to store the exponent'
used for th"e stor"ge ofth" mantissa and the second
a) Using the repreientation above to help you' write
the number
(i) 8.s
ili) -+.s " no"ting-Point number in normalised foim' t6l
", that 8 bits are used for the
iiil sl<pl"t" the efiicts of changing the rePresentation so l2l
mantissa and 4 bits for the exponent.
14'Thedenarynumber-19%istoberePresentedasafloatingpointbinarynumbellsing12bits.The
for the exponent'
irst S bits b. used for the mantissa and the remaining four bits are to be used
"r"io what is meant by the mantissa and exponent of a floating point nlmber' l2l
a. Explain number' t6l
b. Represent the denary number as a normalised floating point binarybinary floating point rep-
I I I 0 as its
.. Ci* the denary number which would have 01000000 -\
for the exponent.
resentation if8 bits are used for the mantissa and 4 bits
t4l
d'Explainwhyitisnotpossibletorepresentzeroasanormalisedfloatingpointnumber.[2]
56
l5' using 8 bits for the mantissa and 6 bits for the exponent, normalise
the following 2s complement
binary numbers:
a) I l0l l0.l l2
b) 0llllll02
c) 0.00010102
t6j
l6',Normalise. the following floating point binary numbers.
The first g bits are used for the Mantissa
and the last 4 bits are used for the exponent.
a) 00011101 0ll0
b) 11000001 1l0l
c) lll0l0l0 0010
lel
17. a) Explain the following character sets,
i) Asclr
ii) BcD
iii) Unicode
iv) EBCDIC
b)For the above character sets, state one advantage and one disadvantage t8l
ofeach. I8l
}-