DATA REPRESENTATION
description
Transcript of DATA REPRESENTATION
![Page 1: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/1.jpg)
DATA
REPRESENTATION
Y. Colette Lemard
February 2009
2
![Page 2: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/2.jpg)
2
TYPES OF NUMBER
REPRESENTATION
![Page 3: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/3.jpg)
3
There are two major classes of number representation :-
FIXED POINT
FLOATING POINT
![Page 4: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/4.jpg)
4
FIXED POINT
SYSTEMS
![Page 5: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/5.jpg)
5
Most of us are familiar with fixed representation to some extent
Let us review it briefly – Binary coded decimal
Signed magnitude (sign & magnitude)
One’s complement
Two’s complement
![Page 6: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/6.jpg)
6
BINARY
CODED DECIMAL
![Page 7: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/7.jpg)
7
B C DIn BCD
representation, we use 4 bits to represent the denary numbers from 1 to 9.
In addition we use 1010 for a positive sign (optional) and 1011 for a negative sign
BCD BCD
0 0000 5 0101
1 0001 6 0110
2 0010 7 0111
3 0011 8 1000
4 0100 9 1001
![Page 8: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/8.jpg)
8
What is the BCD of 947?
1010100101000111
What is the BCD of –836?
1011100000110110
![Page 9: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/9.jpg)
9
What is the denary of the following BCD numbers?
1011011101000101 ?
-745
10100110000000110010 ?
6032
![Page 10: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/10.jpg)
10
SIGNED
MAGNITUDE
![Page 11: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/11.jpg)
11
SIGN AND MAGNITUDE
S&M, as the name suggests, shows both the sign and the size of a number in (usually) one byte. The first bit is usually reserved for the sign and the rest of the bits show the size (or magnitude) of the number.
sign bit : 0 for positive, 1 for negative
![Page 12: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/12.jpg)
12
When converting to S&M binary one would therefore give the binary figure to 7 bits then place the sign bit in front (to the left) of the number.
00000110 6
10000110 -6
01111111 127
11111111 -127
00000000 0
10000000 0
![Page 13: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/13.jpg)
13
When converting S&M binary back to denary one would firstly remove the sign bit then convert the remaining 7 bits. An examination of the sign bit would then determine if the figure is positive or negative.
The range of S&M numbers which can be stored in 8 bits is
-127 to 127
![Page 14: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/14.jpg)
14
ONE’S
COMPLEMENT
![Page 15: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/15.jpg)
15
One’s complement is a binary concept i.e. a number first has to be in binary before we can find its one’s complement.
To find the one’s complement of a number we flip all the bits in the number i.e. change 1’s to 0’s and 0’s to 1’s.
This is called NOTting the number; the NOT of 1 is 0 and the NOT of 0 is 1
![Page 16: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/16.jpg)
16
The one’s complement of a number is a form of the negative of the number.
NumberOne’s Complement
0000 0 1111 0
0001 1 1110 -1
0010 2 1101 -2
0011 3 1100 -3
0100 4 1011 -4
![Page 17: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/17.jpg)
17
Note that both in Sign and
Magnitude and One’s Complement
the number zero has two
representations.
This is inconvenient as making a
comparison for zero then becomes
cumbersome
The Two’s Complement system
addresses this shortcoming
![Page 18: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/18.jpg)
18
TWO’S
COMPLEMENT
![Page 19: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/19.jpg)
19
Most computers
actually use two’s
complement when
manipulating numbers.
![Page 20: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/20.jpg)
20
When you find the two’s complement
of a number you are finding the
negative of that number.
The two’s complement representation
of a positive number is the same as
the straight binary of that number.
![Page 21: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/21.jpg)
21
To find the two’s complement of a
number we first find its one’s
complement then we add 1 to that
number.
Remember to ensure that you are
working in one byte unless told
otherwise.
We ignore/discard any overflows
![Page 22: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/22.jpg)
22
Finding the Two’s Complement of a Denary Number
Find the two’s complement of 72
72 is 1001000
i.e. 01001000 in 8 bits
Flipping the bits gives 10110111
Adding 1 gives 10111000
![Page 23: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/23.jpg)
23
Finding the Two’s Complement of a Denary Number
Find the two’s complement of 31
31 is 11111
i.e. 00011111 in 8 bits
Flipping the bits gives 11100000
Adding 1 gives 11100001
![Page 24: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/24.jpg)
24
Finding the Two’s Complement of a Denary Number
Find the two’s complement of
47 63
81 25
11010001 11000001
10101111 11100111
![Page 25: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/25.jpg)
25
When we look at a number said to be two’s complement we can immediately tell if it is negative or positive by looking at the left most bit
Is this familiar?
![Page 26: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/26.jpg)
26
Converting Two’s Complement to Denary
Look at the leftmost bit
If it is a 1 then use the two’s complement method
If it is a 0 convert as for straight binary
![Page 27: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/27.jpg)
27
Converting to denary from two’s complement
Flip the bits then add 1
![Page 28: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/28.jpg)
28
What denary numbers are these?
11011011 11110010
01101001 10011100
-37 -14
105 -100
![Page 29: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/29.jpg)
29
Because we use the two’s complement system to find the negative of numbers, we can use it to do binary subtraction
This is in fact one of the most useful aspects of two’s complement
![Page 30: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/30.jpg)
30
We firstly need to recall a basic math rule
A – B = > A + ( -B )
This means that we can always substitute an addition for subtraction as long as we can find the negative of the number being subtracted.
![Page 31: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/31.jpg)
31
In binary we can find the negative of a number by using its two’s complement
ThereforeBinaryA – BinaryB
BinaryA
+
(two’s complement of BinaryB)
![Page 32: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/32.jpg)
32
Work in binary and find 7 - 2
7 111 00000111
2 10 00000010 - 2 11111101 + 1 11111110
So 7 - 2 00000111 + 11111110 100000101
Since we are working in 4 bits we discard the leftmost bit so the answer is 000001012
![Page 33: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/33.jpg)
33
Work in binary and find 23 - 11
23 10111 00010111
11 1011 00001011
- 11 11110100 + 1 11110101
(Here I choose to work in 8 bits because 23 is too long for 4 bits)
![Page 34: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/34.jpg)
34
Work in binary and find 23 - 11
So 23 - 11
00010111 + 11110101100001100
Since we are working in 8 bits we discard the leftmost bit so the answer is 000011002
![Page 35: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/35.jpg)
35
Perform the following using two’s complement arithmetic
1. 69 – 26
2. 14 – 5
3. 100 – 50
4. 77 – 33
5. 81 - 81
![Page 36: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/36.jpg)
36
Fixed Point ?
We have been looking exclusively at integers.
An integer can be said to be a number with its decimal point right at the end after the most rightmost digit and with no decimal places after the point.
![Page 37: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/37.jpg)
37
FIXED POINT REPRESENTATION
Integers are an example of fixed point numbers
Fixed Point is so called because the decimal point is steady with there always being the same number of places before and the same number of places after it.
![Page 38: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/38.jpg)
38
Let’s suppose I have 8 bits in which to represent a number in the computer. Remember I can only use 1 and 0.
How do I represent a decimal point?
There is no symbol for the decimal point in binary
![Page 39: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/39.jpg)
39
What I could do however is determine before hand that all numbers are allowed to have 2 decimal places and let the computer system know that this is a general rule.
My byte would be :-
![Page 40: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/40.jpg)
40
I would then have fixed my decimal point to be always after the 2nd position reading from the right. This leaves 6 positions for the whole number part of any value
This seems adequate enough for currency values
But what about very small values measured in science?
![Page 41: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/41.jpg)
41
Maybe I need to use 5 values for the decimal place.
But that would leave only 3 for the whole number.
Seems whatever I do I’m compromising on how large or how small a number my system can store.
![Page 42: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/42.jpg)
42
11111 i.e. 31
Let’s assume that we are working with 8 bits and the decimal point is after the first 5 bits.
What’s the largest integer value I can store if I am using straight binary?
![Page 43: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/43.jpg)
43
What’s the largest number overall?
11111.1112
But what is this in denary?
To answer that we need to understand binary fractions
![Page 44: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/44.jpg)
44
BINARY FRACTIONS
Let us agree on the following about decimals in the denary system
.npxyz
n/101 + p/102 + x/103 + y/104 + z/105 …
n/10 + p/100 + x/1000 + y/10000 + z/100000 …
![Page 45: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/45.jpg)
45
BINARY FRACTIONS
In the binary system therefore
.npxyz
n/21 + p/22 + x/23 + y/24 + z/25 …
n/2 + p/4 + x/8 + y/16 + z/32 …
![Page 46: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/46.jpg)
46
BINARY FRACTIONS
Converting binary fractions to denary
.01001
0/21 + 1/22 + 0/23 + 0/24 + 1/25
1/4 + 1/32 => .28125
![Page 47: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/47.jpg)
47
BINARY FRACTIONS
In the binary system therefore
.11001
1/21 + 1/22 + 0/23 + 0/24 + 1/25
1/2 + 1/4 + 1/32 => .78125.
![Page 48: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/48.jpg)
48
BINARY FRACTIONS
In the binary system therefore
.010111
0/21 + 1/22 + 0/23 + 1/24 + 1/25 + 1/26
1/4 + 1/16 + 1/32 + 1/64 => .359375
![Page 49: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/49.jpg)
49
.1 ½ .05
.01 ¼ .025
.001 1/8 .125
.0001 1/16 .0625
.00001 1/32 .03125
.000001 1/64 .015625
Binary Fractions Table
![Page 50: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/50.jpg)
50
Let us return to our original number 11111.111
We already know that the integer part is 31
The fractional part is => .875
Therefore 11111.1112 = 31.87510
![Page 51: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/51.jpg)
51
Assuming that the decimal point is fixed after the fourth position convert the following binary numbers to denary
1. 00011000 2. 00100100
1.5 2.25
3. 10101010 4. 01111110
10.625 7.875
5. 10011001 6. 11110000
9.5625 15.0
![Page 52: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/52.jpg)
52
What is the largest number and the smallest number that can be held in two bytes assuming that the decimal point is fixed in the centre.
Largest11111111.11111111
510.9960938
Smallest 00000000.00000001
0.0039063
![Page 53: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/53.jpg)
53
Suppose you have a denary fraction and want to know its binary representation?
Us the multiply by 2 with integerr method
(makes sense doesn’t it?)
![Page 54: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/54.jpg)
54
Convert .07510 to binary
.75 X 2 = 1.5
.5 X 2 = 1.0
We stop when we are about ot multiply by zero
Taking the integers reading from the top down gives .112
![Page 55: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/55.jpg)
55
Convert .103610 to binary
.1036 X 2 = 0.2072 (take off the 0)
.2072 X 2 = 0.4144 (take off the 0)
.4144 X 2 = 0.8288 (take off the 0)
.8288 X 2 = 1.6576 (take off the 1)
.6576 X 2 = 1.3152 (take off the 1)
We can continue but lets stop at 5 significant digits
Taking the integers reading from the top down gives .000112
![Page 56: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/56.jpg)
56
Convert .062510 to binary
.0625 X 2 = 0.125 (take off the 0)
.125 X 2 = 0.25 (take off the 0)
.25 X 2 = 0.5 (take off the 0)
.5 X 2 = 1.0 (take off the 1)
We stop here because the next line would see us multiplying by zero
Taking the integers reading from the top down gives .00012
![Page 57: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/57.jpg)
57
Convert to binary
1. .0865
2. .146
3. .149
4. .652
5. .1725
6. .365
![Page 58: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/58.jpg)
58
What is the largest number and the smallest number that can be held in two bytes assuming that the decimal point is fixed with 5 bits following the decimal point.
Largest11111111111.11111
4094.96876
Smallest 00000000000.00001
0.03125
![Page 59: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/59.jpg)
59
What is the largest number and the smallest number that can be held in two bytes assuming that the decimal point is fixed with 2 bits following the decimal point.
Largest11111111111111.11
131070.75
Smallest 00000000000000.01
0.25
![Page 60: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/60.jpg)
60
One therefore compromises on the whole number in order to get more precision on the fraction or can accommodate only a limited number of fractions in order to get a larger whole number.
![Page 61: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/61.jpg)
61
Though we can store fractions using fixed point representation the range of numbers is very limited. Even using 32 bits (one word on a modern pc) and using 8 bits for the fraction we can hold a maximum of just over 8 million
![Page 62: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/62.jpg)
62
101.01 is 5.25
101.10 is 5.5
101.11 is 5.75
We can not get in between those values so it is impossible to
accurately represent 5.4 or 5.65
![Page 63: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/63.jpg)
63
For denary fractions we get down to 1/10th of a value but with binary fractions only .5, or .5 of .5, or .5 of .5 of .5.
Trying to map an infinite number of values onto a finite number of bit patterns results in loss of precision because rounding off is needed.
![Page 64: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/64.jpg)
64
Advantages of Fixed Point Notation
Simple arithmetic
Faster processing
![Page 65: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/65.jpg)
65
Disadvantages of Fixed Point Notation
Loss of precision
Limited range of numbers can be represented
![Page 66: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/66.jpg)
66
Questions ?
![Page 67: DATA REPRESENTATION](https://reader036.fdocuments.in/reader036/viewer/2022062321/568140eb550346895dacba16/html5/thumbnails/67.jpg)
67
~ The E N D ~