Data Representation Book 1
Data Representation Book 1
Data Representation
Chapter Objectives
Learners should be able to:
Introduction
Data representation is concerned with the way data in the computer is processed, stored and even
transmitted. Computers are basically classified as digital, analogue or hybrid. Digital computers
process data in discrete form whereas analog computers process data that is continuous in nature.
Hybrid computers process both discrete data and continuous data. A computer can store different
forms of data which can range from sound, images, videos, numbers or text. Digital computers
process data in two states ON and OFF. The ON state is represented by a “0” and the OFF state is
represented by a “1”. The values “0” and “1” are known as binary digits (Bits)
Example
Convert 21 into binary
2 21
2 10 R 1
2 5 R 0
2 2 R 1
2 1 R 0
0 R 1
We write down the remainders from bottom upwards to get the answer 101012
1
Example
Convert 12.75 into binary
2 12
2 6 R 0
2 3 R 0
2 1 R 1
2 0 R 1
(ii) The next stage is to convert the decimal fraction .75 to a binary representation
– Multiply the decimal fraction by 2. The whole number part of the result is the first binary
digit to the right of the point.
.75 x 2 = 1.5, the first binary digit to the right of the point is a 1.
– Next we disregard the whole number part of the previous result (the 1 in this case) and
multiply by 2 once again. The whole number part of this new result is the second binary
digit to the right of the point
– We will continue this process until we get a zero as our decimal part or until we
recognise an infinite repeating pattern.
– In fact, we do not need to continue because we had 0 as the fractional part of our result
there.
– Hence the representation of 12.75 = 1100.112.
– If for example, we are converting a binary fraction to decimal and we notice that the steps
to be performed are exactly the same action 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 of our result but going
to have a repeating pattern.
– For example, 3.1 converted to binary will produce the following repeating pattern:
11 .00011001100110011 . . . (base 2)
2
0011 is a repeating pattern.
– Therefore, 3.1 in binary will be 11.000112
Example
Convert 5.37510 into binary
2 5
2 2 R 1
2 1 R 0
2 0 R 1
(ii) The next stage is to convert the decimal fraction .375 to a binary representation
0.375 x2 0.750 (0 becomes the first value after the binary point)
0.750 x2 1.500 (1 becomes the second value after the binary point)
1.500 x2 1.000 (1 becomes the third value after the binary point)
(fractional part becomes 0, so we stop)
Example
Convert 11100 into denary
Power 24 23 22 21 20
Equivalent to: 16 8 4 2 1
Binary Digits 1 1 1 0 0
3
Example
Convert 101.11 into denary
Example
Convert 1111.11000 into denary
28 27 26 25 24 23 22 21 20 . 21 22 23 24 25
256 128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
0 0 0 0 0 1 1 1 1 .1 1 0 0 0
– The following shows the equivalent representation of an integer binary number and a
fractional binary number
28 27 26 25 24 23 22 21 20 . 21 22 23 24 25
256 128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 0.03125
1 0 0 0 0 0 0 1 1 1 1 1 0 0
4
256+2+1+0.5+0.25+0.125 = 259.37510
Activity 1
Example
Convert 8810 into octal
8 88
8 11 R 0
8 1 R 3
0 R 1
Example
Covert 27 into octal
8 27
8 3 R 3
0 R 3
5
– Therefore, 2710 = 338
Example
Convert 23.015625 into octal
8 23
8 2 R 7
0 R 2
(iii) The next stage is to convert the decimal fraction .015625 to an octal representation. We
perform the same procedure as we did in binary but in this case we multiply by 8.
Example
Convert 1678 into denary
Power 84 83 82 81 80
Equivalent to: 4 096 512 64 8 1
Octal Digits 1 6 7
64 + 48 + 7 = 11910
6
Example
Convert 17.528 into denary
17 = (1x81) + (7x80)
=8+7
= 158
.52 = (5x8-1) + (2x8-2)
= 5/8 + 2/64
= 0.625 + 0.03125
Activity 2
Decimal number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal equivalent 0 1 2 3 4 5 6 7 8 9 A B C D E F
7
Example
Covert 20610 into hexadecimal
16 206
16 12 R 14
0 R 12
Example
Convert 97.3510 into hexadecimal
16 97
16 6 R 1
0 R 6
(iv) The next stage is to convert the decimal fraction .35 to hexadecimal representation. We
perform the same procedure as we did in binary and octal but in this case we multiply
by 16.
Example
Convert D116 into denary
(Dx161) + (1x160)
8
(13x16) + (1x1)
208 + 1= 20910
Example
Convert A7.4D16 into denary
A7 = (Ax161) + (7x160)
= 160 + 7
= 16716
.4D = (4x16-1) + (Dx16-2)
= (4x16-1) + (13x16-2)
= 0.25 + 0.05078125
Activity 3
(k) Conversion from binary to octal and hexadecimal and vice versa
– A relationship exists between binary, octal and hexadecimal numbers which makes
conversion of binary to octal and hexadecimal and conversion of octal and hexadecimal to
binary to be done straight away with minimum amount of calculations.
9
– 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 10001110101012 to octal
(i) Group the bits in 3s starting from right going to the left
Example
Convert 5278 into binary
5 2 7
1012 0102 1112
(ii) Take the binary digits and join them into one binary number
101010111
Example
Convert 111000111010101 into hexadecimal
(i) Group the bits in 4s starting from right going to the left
Example
Convert 5CA16 to binary
5 C A
01012 11002 10102
11
(ii) Take the binary digits and join them into one binary number
0101110010102
Activity 4
a) octal b) hexadecimal
Binary System
– Using binary system the data is represented in two possible states, that is, 0 and 1, thus in
base 2.
– Most computing devices use the binary number system to represent electronic circuit
voltage state, which considers 0 voltage input as off and 1 voltage input as on.
– The sequence of ON’s and OFF’s forms the electrical signals that the computer can
understand.
– The 0 or 1 is known as a binary digit.
12
– It is easier to construct electric circuits based on only two binary values 0 and 1 or ON and
OFF logic rather than construct devices that can understand natural language due to the
different forms of natural languages.
– Binary data is also reasonable simple to store - again only needing a two state storage
(On/Off).
– Calculations can be carried out using reasonably simple active electronics (simple
transistor circuits), since it only requires on and off (1 and 0) signals.
– All forms of data can be represented in binary system format.
– Digital devices are more reliable, small and use less energy as compared to analog devices.
– Binary codes are suitable for the computer applications and digital communications.
Binary Arithmetic
– Addition, subtraction, multiplication and division can be performed on binary numbers in
a similar way as we perform the arithmetic operations on denary numbers (base ten).
Binary Addition
– In decimal addition, if you add 7 + 3 you get 10; in the sum this gives a digit 0 and a
carry of 1.
– Similarly in binary addition when you add 1 and 1; the result is two, written as 10 in
binary, we get, a digit 0 and a carry of 1.
– Therefore in binary:
0+0=0
0+1=1
1+0=1
1 + 1 = 10 (which is 0 carry 1)
Example
100101 + 10101
Explanation
100101
+ 10101
111010
13
sixth column : 1 + 0 + no carry = 1
Example
Find the sum of the binary numbers 10111 and 110101
11111 Carry
10111
+ 110101
1001100
Example
Find the sum of the binary numbers 10001 and 11101
1 1 Carry
10001
+ 11101
101110
Binary Subtraction
– Just like in decimal subtraction, if you must subtract a one from a zero, you need to
“borrow” from the left.
Example
1011011 − 10010 = 1001001:
1011011
− 10010
1001001
Example
1010110 − 101010
0 0
1 10 1 10 1 1 0
− 1 01 010
1 01 100
Binary Multiplication
– Binary multiplication is actually much simpler to calculate than decimal multiplication.
– In the case of decimal multiplication, we need to remember 4 x 9 = 36, 7 x 7 = 49, and so
on.
– In binary multiplication, we only need to remember the following:
14
0x0=0
0x1=0
1x0=0
1x1=1
Example
Multiply 101 by 11
1 1 0 1
x 1 1
Explanation
1 1 0 1
x 1 1
1 1 0 1
1 1 0 1 0 The 0 is the placeholder
The results from our previous step indicates that we must add 1101 and 11010, the sum of which
is 100111.
1 1 0 1
x 1 1
1 1 0 1
1 1 0 1 0
1 0 0 1 1 1
Example
1 0 1 1. 0 1
x 1. 1
1 0 1 1 0 1
1 0 1 1 0 1 0
1 0 0 0 0 .1 1 1
– 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.
15
– 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
Binary Division
– Binary division involves knowledge of binary multiplication.
Example
11 R 10
11 )1011
-11
101
-11
10 <-- remainder, R
OR
11.101010
11 )1011.000000
-11
101
-11
100
-11
100
-11
100
-11
10
– 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 10 and it will continue. So it’s
better to stop at four or six fractional bit places and settle for 11.1010 or11.101010
16
1011 /11 = 11 R 10
To check our answer, we first multiply our divisor 11 by our quotient 11. Then we add its'
product to the remainder 10, and compare it to our dividend of 1011.
11
x 11
11
+ 11
1001 <-- product of 11 and 11
1001
+ 10
1011 <-- sum of product and remainder
Example
10111 divided by 10
101_ R=1
10 )1011
-10
11
-10
1<-- remainder, R
Example
10.111 divided by 0.10
Step 1
Remove the binary point from the divisor by moving it two steps to the right.
0.10 becomes 010
Step 2
We must also move the binary point same number of steps to the right as we did on the divisor.
Remember to add 0 bits as needed to fill the new spaces.
10.111 becomes 1011.1
Step 3
Discard/ignore the leading zeros on the divisor. Then continue with the division using the two
binary numbers as follows:
1011.1 / 10
17
101.11_
10 )1011.1
-10
11
-10
11
-10
10
-10
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 1010. In the binary system, you borrow a group of 2 10. In the octal system you
borrow a group of 810.
Octal Addition
Example
168 + 58
1 Carry
16
+ 5
23
18
Example
2568 + 2238
11
Carry
256
+223
501
Octal Subtraction
Example
3568 -2738
1 8 Borrow
2
356
-2 73
63
Example
6548 - 1368
8 Borrow
6 45 4
-13 6
51 6
Hexadecimal Arithmetic
– The addition and subtraction of hexadecimal numbers also 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 hexadecimal system, you borrow a
group of 1610.
Uses of Hexadecimal
– To store instructional codes in the computer.
– To represent locations of data in memory (memory addresses).
– To represent web pages colours, for example, #FF0000 represents a red colour.
19
Decimal number 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal equivalent 0 1 2 3 4 5 6 7 8 9 A B C D E F
Example
4C616 + 2B216
1 Carry
4C6
+2B2
77 8
Example
4C616 + 2B216
1 Carry
4C6
+2B2
77 8
Hexadecimal Subtraction
Example
3568 -2738
1 8 Carry
2
356
-2 73
63
Example
3A516 -1B216
16 Carry
2
3A 5
-1 B 2
1 F 3
Activity 7
20
(v) 678 + 258
(vi) 1248 + 2718
(vii) 5148 – 278
(viii) 4628 – 768
Integer Representation
– Computers use a fixed number of bits to represent an integer, for example, 8-bit, 16-bit,
32-bit or 64-bit.
– Two representation schemes are used for integers:
a) Unsigned integers: can represent zero and positive integers.
b) Signed integers: can represent zero, positive and negative integers.
(-2n ) to (+2n-1)
where n is the number of bits excluding the sign bit
0 1 1 1 1 1 0 0
Sign bit Magnitude
Example
Using 8 bits, find the range of numbers that can be represented using sign and magnitude
(-2n ) to (+2n-1)
(-27 ) to (+27-1) n = 7 not 8 because the other bit is for the sign bit
(-128) to (+128-1)
-128 to +127
– Thus, an 8-bit signed number can represent data in the range -12810 to +12710.
21
Example
Using 8-bits represent 15 in sign and magnitude
Sign bit: 0
Magnitude: 0001111
Example
Using 8-bits represent -20 in sign and magnitude
Sign bit: 1
Magnitude: 0010100
1s Complement
– 1s complement can be used to represent both positive and negative numbers.
– Positive numbers do not change and they are represented as usual.
– If a number is negative we can represent it using one’s complement by applying the bitwise
NOT to the number.
– Bitwise NOT is an operation on only one operand that performs logical negation on each
bit. For example, the bitwise Not of 10102 is 01012.
– Simply, in one’s complement, 0s are negated to 1s while 1s are negated to 0s.
– The range of numbers that can be represented in 1’s complement is found by the formula:
- (2n-1-1) to + (2n-1-1)
where n is the number of bits to represent the number
Example
Using 4-bits, find the range of numbers that can be represented using 1s complement.
- (2n-1-1) to + (2n-1-1) n = 4
- (24-1-1) to + (24-1-1)
- (23-1) to + (23-1)
22
- (8-1) to + (8-1)
-7 to +7
– Therefore, the largest number that can be represented is +7 and the smallest is -7.
Example
Using 8-bits represent (i) -10 and (ii) -2 (iii) +7 in 1’s complement
(i) +10 = 000010102
-10 = 111101012
(ii) +2 = 000000102
-2 = 111111012
(iii) +7 = 00001112
-7 = 11110002
Addition in 1s Complement
– Addition is performed 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
Subtraction in 1s Complement
– The main purpose of using ones complement in computers is to perform binary subtraction.
– Subtraction is achieved by first performing the 1s complement operation on the number
being subtracted then adding the two numbers.
Example
Using 8-bits, find 8 – 4 in ones complement
23
8 000010002
+ (-4) 111110112
[1]000000112
12 Overflow bit is added to give the answer 000001002
4 000001002
2s Complement
– Modern computers use two’s complement to represent positive and negative numbers in
binary.
– The useful part of two’s complement is that it automatically includes the sign bit.
Advantages of 2s Complement
– Twos 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 (not need to implement
adders and subtractors).
– Zero has only a single representation, unlike in ones'-complement where it has two values
11111111 (-0) and 00000000 (+0).
– Twos complement enables higher precision arithmetic to be handled.
Example
Using 4-bits represent 7 in 2s complement
7 = 101
– Therefore, 7 = 01012
Example
Using 8- bits represent 9 in 2s complement
9 = 10012
– Therefore, 9 = 000010012
24
– Negative numbers are represented using a 2's complement form.
– To obtain the 2's complement of a number:
Method 1
(i) Convert the number to its binary equivalent, if it is not in binary.
(ii) Change the number to one’s complement (Change the 0’s to 1s and 1s to 0s)
(iii) Add 1 to the result
Method 2
(i) Write the bits starting from the right hand side.
(ii) Take all 0s as they are at their respective position including the first 1 value
encountered in the binary number.
(iii) Thereafter change 1s to 0s and 0s to 1s 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 01112
1s complement 10002
Add 1 + 1
10012
-7 = 10012
(ii)
+3 00112
1s complement 11002
Add 1 + 1
11012
-3= 11012
Addition in 2s Complement
– Addition is performed by doing the simple binary addition of the two numbers.
Example
25
Using 5- bits, find the sum of 9 and 5
9 010012
+5 001012
14 011102
Subtraction in 2s Complement
– Subtraction is achieved by first performing the 2s complement operation on the number being
subtracted then adding the two numbers.
Example
Using 8-bits, find 25 - 29
25 0001 10012
+ (-29) 1110 00112 (+29 = 0001 11012)
-4 1111 1100 2
Example
Using 4-bits, find 6 – 6
6 01102
+( -6) 10102
0 [1]00002
Overflow bit is thrown away to give answer as 0000 which is 0.
Example
This is the same as -63 + (-94). Therefore, convert -63 and -94 into 2s complement and add the
two numbers.
(-63) 110000012
+(-94) 101000102
[1] 011000112
– Throw away the carry bit 1, to get the final answer as 01100011.
– The extra bit 1 indicates overflow.
– The result above indicates overflow as the result of adding two negative numbers cannot
give a positive answer.
26
– For negative numbers, we first convert it back to a normal binary number and then prefix
the denary number with a negative (-) sign.
– A positive number starts with a zero (0) and a negative number starts with a one (1)
– The process of converting from binary 2s complement to denary is accomplished using the
following steps:
(i) Complement the binary number (Convert zeros to ones and ones to zeros)
(ii) Add one to the binary number
(iii) Convert binary number to decimal
(iv) Prefix a minus sign
OR
Example
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
0 1 0 0 0 0 0 1
= 64 + 1
= 65
Example
11100010
Complement the number 00011101
Add 1 +1
00011110
27
– With twos complement representation there is no bit allocated as the sign bit but the left-
most bit behaves like one.
– Unsigned range refers to how many numbers you can represent if you only allow positive
numbers (no sign is needed).
– Signed range refers to how many numbers you can represent if you require both positive
and negative numbers.
– Therefore, twos complement range is a signed range since it represents both positive and
negative numbers.
– For example, the range of 8-bit values if they are stored using unsigned numbers will be
from 00000000 (0) to 11111111 (255), while the signed two's complement range is from
10000000 (-128) to 01111111 (127).
– The following formulae can be used to find the largest number and smallest number that
can be represented in 2s complement:
- (2n-1) to + (2n-1-1)
where n is the number of bits used to represent the number
Example
Find the largest number that can be represented in 8-bit 2s complement
- (2n-1) to + (2n-1-1)
- (28-1) to + (28-1-1)
- (27) to + (27-1)
-128 to + 127
– Therefore, and the smallest number is -128 = (100000002 ) and the largest number is
127 = (011111112).
– Using 8-bits to represent a number, if the result of calculation produces a result above +127
then it is called overflow.
– If the result produced is less than -128 then it is called underflow.
Activity 8
2. Using 4-bits what is the largest and smallest numbers that can be represented in
(a) sign and magnitude
(b) 1s complement
(c) 2s complement
28
(ii) 14 – 8
(iii) -21- 8
* * * * * * * *
The overall range of numbers that can be represented is given by the following formulae:
-2n-1 to 2n-1-1
29
where n is the number of bits to represent the number
Example
Using 8-bits, find the range of numbers that can be represented
-2n-1 to 2n-1-1
-28-1 to 28-1-1
-27 to 27-1
-128 to + 127
1 0 1 1 0 1 1 1
Binary point
– The following shows an 8-bit fixed point fractional binary number with an imaginary
binary point after the fifth digit
10001001
– Using 2s complement negative numbers start with a 1 and positive numbers start with a 0.
30
Example
Using 1 byte to hold each number, with an imaginary binary point fixed after the fourth digit,
convert the decimal number 8.5 to binary.
8 = 1000
.5 = .1
Example
Assuming 3 bits after the imaginary binary point, convert the binary number 0000011011 to
decimal.
0000011011
0000011.011
26 25 24 23 22 21 20 . 21 22 23
64 32 16 8 4 2 1 0.5 0.25 0.125
0 0 0 0 0 1 1 .0 1 1
= 2 + 1 + 0.25 + 0.125
= 3.375
Example
Represent -7.2510 in 8-bit binary with the binary point after the fourth digit.
31
Advantages of the Fixed Point Binary System
1. 7.23 x 102
2. 72.3 x 101
3. 723 x 100
4. 0.723 x103
5. 7230 x 10-1
0.723 x 103
Mantissa Exponent
– This means we need only store the mantissa 0.723 and the exponent 3 means we move
the decimal point three places to the right.
32
– The same can be done in binary and this forms the foundation of our floating point
number.
– The floating point number will be represented as follows:
Mantissa x 2Exponent
– Since we need only to store the mantissa and exponent the binary floating number is
represented as follows:
Mantissa Exponent
– Using 8-bits for the mantissa and 4-bits for the exponent the binary number 0.0001111can be
represented as follows:
(i) 0.0001111 x 20
00001111 0000 (Mantissa: 00001111 Exponent: 0000)
(ii) 0.0011110 x 2-1
00011110 1111
(iii) 0.0111100 x 2-2
00111100 1110
(iv) 0.1111000 x 2-3
01111000 1101
The exponent becomes 4 since we have to move the binary point 4 steps to the right to get back
to the original binary number.
0.111011 x 24 (000100)
01110110 00100
Example
Represent the binary number 11110 in floating point with a 6-bit mantissa and 5-bit exponent.
33
Move the binary point 5 steps to the left to get 0.11110
The exponent becomes 5 since we have to move the binary point 5 steps to the right to get back
to the original binary number
0.11110 x 25 (00101)
Mantissa: 011110
Exponent: 00101
011110 00101
The following are the stages to follow when converting a denary number into binary floating
point:
Example
Convert the denary number 39.75 into binary floating point.
27 26 25 24 23 22 21 20 . 21 22 23
128 64 32 16 8 4 2 1 0.5 0.25 0.125
0 0 1 0 0 1 1 1 .1 1 0
00100111.110
Move the binary point 6 steps to the left to get the following:
00.100111110
To get our decimal point back to where it started, we need to move 6 places to the right (6 now
becomes the exponent)
0.100111110 000110
Example
Convert the denary number -13. 25 to a floating-point binary representation with 8-bits for the
mantissa and 4-bits for the exponent.
34
24 23 22 21 20 . 21 22 23
16 8 4 2 1 0.5 0.25 0.125
0 1 1 0 1 .0 1 0
Move the binary point 4 steps to the left to get the following:
1.0010110
To get our decimal point back to where it started, we need to move 4 places to the right.
Therefore, 4 now becomes the exponent.
1.0010110 0100
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 twos complement.
Show the following floating point in its denary equivalent:
a) 01111 011
b) 11000 110
a) 01111 011
01111 011
35
The exponent is 011 (3 in denary)
Therefore, move three steps to the right to get the original binary number
01111 becomes 111.1
22 21 20 . 21
4 2 1 0.5
1 1 1 .1
111.1
= 4 + 2 + 1 + 0.5
= 7.5
b) 11000 110
11000 110
The exponent is 110 (-2 in denary). Therefore, move 2 steps to the left to get the original binary
number
01000 becomes 00010
= 0 + 0+ 0 + 0.125
= 0.125
= -0.125 (Since the mantissa is negative)
36
– A number can have different representations, for example, in binary, 0.0001111can be
written as follows:
00001111 0000
00011110 1111
00111100 1101
Activity 9
1. 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 twos complement.
Show the following floating point in their denary equivalent:
(a) 11111 011
(b) 01011 111
2. Work out the binary floating point for the denary number 97, using 10 bits for the mantissa
and 6 bits for the exponent.
– For a floating point binary number to be normalise, the first two bits must be different.
That is:
1.0 or 0.1 and definitely NOT 1.1 or 0.0
– Thus, if the mantissa is positive, the Sign Bit is always 0 and the MSB is always 1(0.1).
– If the mantissa is negative, the Sign Bit is always 1 and the MSB is always 0(1.0).
– For a negative number, there must be NO leading 1s to the left of the MSB, except the sign
bit.
37
1.1100111
– For a positive number, there must be NO leading 0s to the left of the MSB, except the sign
bit.
0.0101111
– With positive numbers, the binary point in the mantissa is always placed immediately
before 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 the first two
digits are the same.
– A normalised value must have the first two bits of the mantissa different. Usually, the
computer 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.
– To maximise the precision of a negative number you should have a mantissa with no
leading ones.
The mantissa is positive. The number starts with 0.01 and we need to change this so that it starts
with 0.1for it to be normalised. To do this we need to move the binary point one position to the
right. We must subtract one from the exponent to compensate for the movement of the decimal
place one place left.
0.100000000 | 000010
Or
38
(b) Normalise the following floating point number 1.110000000 | 111110
The mantissa is also negative. It starts with 1.11 and we need to change this so that it starts with
1.0 for it to be normalised. To do this we need to move the binary point two positions to the right.
We must subtract two from the exponent to compensate for the movement of the decimal place
two places left.
1.000000000 | 111100
Move the binary point 3 positions to the right to get the following:
0.101011
Compensate for the number of bits by appending two 0s to get the following:
0.10101100
The exponent becomes -3 since the binary point has to move 3 steps to the left to get back to the
original binary number.
Example
Using 8 bits for the mantissa and 5 bits for the exponent, normalise the binary number
011101.11
Move the binary point 5 positions to the left to get the following:
0.1110111
The exponent becomes 5 since the binary point has to move 5 steps to the right to get back to the
original binary number.
39
0.1110111 x 23(00101)
Mantissa: 010000
Exponent: 1100
Example
Convert the following normalised number to decimal
1011000 1110
Mantissa: 1011000
Exponent: 1110
40
1 0.5 0.25 0.125 0.0625 0.03125 0.015625
0 .0 0 1 0 1 0
Example
Convert the following normalised number to decimal
010101 0100
Mantissa: 010101
Exponent: 0100
24 23 22 21 20 . 2-1
16 8 4 2 1 0.5
0 1 0 1 0 .1
8 + 2 + 0.5 = 10.5
20 . 2-1 2-2
0 0.5 0.25
0 .0 1
0.01
41
Append three 0s to make the mantissa 6 bits.
0.01000
The exponent becomes 1111 (-1 in denary since the binary point must move 1 step to the left to
get back to the original value)
Example
Change the decimal fraction -5.25 to normalised floating point number using 8-bits mantissa and
4-bits exponent.
Convert the fraction -5.25 to binary ignoring the negative sign to get the following:
22 21 20 . 2-1 2-2
4 2 1 0.5 0.25
1 0 1 .0 1
101.01
The exponent becomes 0011 (3 in denary since the binary point must move 3 steps to the right to
get back to the original value)
Example
Normalise -1/8, given it has 6 bits for the mantissa and 4 bits for the exponent.
Convert the fraction -1/8 to binary ignoring the negative sign to get the following:
0.001
42
1
/8 = 0.00100
The exponent becomes 1101 (-3 in denary since the binary point must move 3 steps to the left to
get back to the original value)
Therefore, -1/8 becomes 100000 1101 in normalised floating point.
Advantages of Normalisation
– Ensures that a single representation of a number is maintained (standardisation).
– Ensures maximum possible accuracy is maintained with a given number of bits.
– Saves space by using the space given in an efficient way.
– Can be used to detect error conditions such as underflow and overflow
– Tries to maximise the range of numbers that can be represented in a fixed point
representation (range and accuracy is limited in fixed point representation).
43
– The largest positive value we can have for the mantissa is 0.1111111.
– The largest positive number we can have for the exponent is 01111111.
– This means that we have 0.1111111 x 21111111 = 0.1111111 x 2127.
– This means that the largest positive number is almost 1 x 2 127.
Also:
– The smallest positive mantissa is 0.1000000.
– The smallest negative exponent is 10000000.
– This represents 0.1000000 x 210000000 = 0.1000000 x 2-128 which is very close to zero;
in fact it is 2-129.
Activity 10
1. Using 10-bit mantissa and a 6-bit exponent, normalise the following numbers:
2. What is the decimal value for the following binary patterns if the first 8 bits is the mantissa
and the last 4 bits are the exponent?
44
(a) 10101100 0110
(b) 0101 0000 1100
3. Using 10-bit mantissa and 6-bit exponent, represent the following decimal numbers using
normalised floating point representation:
(a) 25.275
(b) -8.5
(c) 143
Truncation Errors
– Truncation is shortening by cutting off some 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 "chopped 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:
45
Overflow and Underflow
– Since we are working with numbers contained in a fixed number of bits, we must be able
to detect overflow and underflow errors following an operation.
– In signed binary arithmetic, overflow and underflow indicate errors.
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 of bits 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 off produces a result number with the sign
bit on.
4 0100
4 + 0100
-- ------
8 1000 (Overflow has occurred because 8 is out of range)
– Using 4 bits, the range of numbers to be represented is 1000 (-8) to 0111 (+7)
(ii) The sum of two numbers with the sign bits on produces a result number with the sign
bit off.
8 1000
+ 8 +1000
-- ------
16 10000 (Overflow has occurred because 16 is out of range)
– If you are doing two's complement (signed) arithmetic, overflow occurs when;
(i) Suppose x and y both have sign bits with value 1. That means both represent negative
numbers. If the sum has sign bit 0, then the result of adding two negative numbers has
resulted in a 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 1, then the result of adding 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 the
answer is wrong.
– If you are doing unsigned arithmetic, the overflow flag means nothing and should be
ignored.
46
b) Underflow
– Underflow occurs where the result of a calculation is of very 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 multiplied together.
-9 1001
+-7 +0111
---- ------
-16 10000 (Underflow has occurred because -16 (10000) is smaller than -8
(1000) which is the smallest number that can be represented)
– Using 4 bits, the range of numbers to be represented is 1000 (-8) to 0111 (+7)
– The solution to overflow and underflow is to use more bits. Know ahead of time the
minimum and maximum values expected.
Activity 11
Perform a calculation on the following signed binary numbers and indicate whether they
produced an overflow or not:
i) 1000 + 1000
ii) 0100 + 0001
iii) 0110 + 1001
iv) 0000 + 0001
v) 1100 + 1100
Actual error
– Actual error or absolute error is the difference between the exact/actual value and the
computed value.
– Actual error is obtained by the following formulae:
Relative error
– Relative error is obtained by the following formulae:
Relative error= Actual error/Exact value
Example
2/3 is approximated to 0.666. Find the actual error and relative error.
47
Computed value = 0.666
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 text, number or even symbols.
– Each character is represented by a number, for example, the ASCII character set uses
numbers 0 through 127 to represent all English characters and special symbols.
– The following are examples of character set used by general computers to represent
characters:
American Standard Code for Information Interchange (ASCII)
Unicode
Binary Coded Decimal (BCD)
Extended Binary Coded Decimal Information Code (EBCDIC)
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 digits.
– 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.
– ASCII-8 allows 256 characters to be represented, that is, 28 = 256 combinations.
– ASCII-8 has 4 bits for zone and 4 bits for the digit.
48
49
– Codes 0 to 31and 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-Z.
– Codes 97 to 122 stand for lowercase letters a-z.
– Codes 128 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 '1'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 118 101 since 006 represents F, 105
represents i, 118 represents v and 101 represents e. This will translate to 00000110
01101001 01110110 01100101 in binary.
– It is important to note that “120” is treated as 3 characters in ASCII, which is different to
the number 358.
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
50
– The decimal number 41 is coded as 0100 0001
– The decimal number 9212 is thus coded as 1001 0010 0001 00102 in BCD.
The first digit, 1 is wrong and 1010 does not exist in BCD. The error is caused by the
range of numbers used for representing data in BCD. BCD uses 4 bits which is 2 4 = 16
combinations. However, the maximum range of numbers that can be represented is 9. If
the sum of bit is greater than 9 then 6 has to be added to the result. Thus adding the result
above, 0001 10102 to 6 (0110) gives us 0010 00002, which is 20 in BCD.
51
– Unlike ASCII there is no "free" bit which can be used for error detection. If a computer
using this code for internal representation is to be connected to a data transmission
system, the data will generally have to be converted to ASCII before transmission.
Unicode
– Unicode is enough to represent around 120,000 different characters in any language,
English, Chinese and even hieroglyphics.
– Unicode is a universal character encoding standard for the representation of letters,
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 that applies across different platforms
and programs.
– The most widely used Unicode encoding schemes are called UTF-8, UTF-16, and UTF-
32.
– UTF-16 is a variable length which uses 16 bits or 32 bits whereas UTF-32 is a fixed
length which uses 32 bits.
– UTF-8 is commonly used and it is a variable length as it contains either 8, 16, 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 binary representation of
00110010 whereas the Chinese character is represented by a Unicode number
35987 which translates to 11101000 10110010 10010011 in binary.
– Most Microsoft Software and Linux distributions use Unicode.
Activity 12
1. Represent the following decimal numbers in BCD:
(i) 567
(ii) 21
2. Using the ASCII table, determine the binary equivalence of the following characters:
(i) M
(ii) 7
(iii) &
52
3. Representation the following in ASCII:
(i) Data.
(ii) A byte.
Revision
1. Calculate the number of bytes found in the following:
a) 2 Kilobyte (Kb)
b) 3 Megabyte (Mb)
c) 4 Gigabyte (Gb)
d) 5 Terabyte (Tb) [8]
a) 1010 / 10
b) 1010 / 11
c) 10.11 / .010
d) 11100 – 1101
f) 101011 x 110
g) 101.1 x 1.01
53
5. Perform the following binary arithmetic and indicate whether an overflow has occurred.
a) 0110 + 0001
b) 0100 + 0001
c) 0111 + 0001
d) 0110 + 1001
e) 1000 + 0001
f) 1100 + 1100 [12]
6. The sum of 2.39 and 1.498 is to be worked using only 3 significant figures.
Find the actual error and relative error if truncation is used. [6]
a) 56 b) 78 c)108 [6]
a) 1010
b) 11.0001
b) 11.11 [6]
a) 345
b) 25.575
c) 0.25 [6]
10. a) Using an appropriate number of bytes in each case, express the number 10310 in
(i) binary
(ii) BCD [4]
b) Using the answer obtained in part (a) show how 10310 can be expressed in
(i) octal (ii) hexadecimal with a minimum amount of calculation. [8]
54
12. a) Using a single byte for each answer, explain how the denary number –29 can be
represented in binary in
(i) sign and magnitude
(iii) 1s complement
(ii) 2s complement [6]
b) (i) Convert -54 and -104 into 2’s complement, 8 bit, binary numbers. [4]
(ii) Add the binary values obtained in b)(i) together. [2]
(iii) Comment on the result that you obtained in b)(ii). [2]
13. Floating-point numbers in a particular computer system are stored using 12 bits. The first 6
bits are used for the storage of the mantissa and the second set of 6 bits is used to store the
exponent.
14. The denary number -19¾ is to be represented as a floating point binary number using 12 bits.
The first 8 bits are to be used for the mantissa and the remaining four bits are to be used for
the exponent.
a) Explain what is meant by the mantissa and exponent of a floating point number. [2]
b) Represent the denary number as a normalised floating point binary number. [6]
c) Give the denary number which would have 01000000 111 0 as its binary
floating point representation if 8 bits are used for the mantissa and 4 bits
for the exponent. [4]
d) Explain why it is not possible to represent zero as a normalised floating point number. [2]
15. Using 8 bits for the mantissa and 6 bits for the exponent, normalise the following 2s
complement binary numbers:
a) 110110.112
b) 011111102
c) 0.00010102 [6]
16. Normalise the following floating point binary numbers. The first 8 bits are used for the
Mantissa and the last 4 bits are used for the exponent.
a) 00011101 0110
b) 11000001 1101
c) 11101010 0010 [9]
b) For the above character sets, state one advantage and one disadvantage of each. [8]
55