Presentation is loading. Please wait.

Presentation is loading. Please wait.

DATA REPRESENTATION Y. Colette Lemard February 2009 2.

Similar presentations


Presentation on theme: "DATA REPRESENTATION Y. Colette Lemard February 2009 2."— Presentation transcript:

1 DATA REPRESENTATION Y. Colette Lemard February 2009 2

2 2 TYPES OF NUMBER REPRESENTATION

3 3 There are two major classes of number representation :- FIXED POINT FLOATING POINT

4 4 FIXED POINT SYSTEMS

5 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

6 6 BINARY CODED DECIMAL

7 7 B C D In 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 0000050101 1000160110 2001070111 3001181000 4010091001

8 8 What is the BCD of 947? 1010100101000111 What is the BCD of –836? 1011100000110110

9 9 What is the denary of the following BCD numbers? 1011011101000101 ? -745 10100110000000110010 ? 6032

10 10 SIGNED MAGNITUDE

11 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

12 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. 000001106 10000110-6 01111111127 11111111-127 000000000 100000000

13 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

14 14 ONE’S COMPLEMENT

15 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

16 16 The one’s complement of a number is a form of the negative of the number. Number One’s Complement 0000011110 000111110 001021101-2 001131100-3 010041011-4

17 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

18 18 TWO’S COMPLEMENT

19 19 Most computers actually use two’s complement when manipulating numbers.

20 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.

21 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

22 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

23 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

24 24 Finding the Two’s Complement of a Denary Number Find the two’s complement of 4763 8125 1101000111000001 1010111111100111

25 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?

26 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

27 27 Converting to denary from two’s complement Flip the bits then add 1

28 28 What denary numbers are these? 1101101111110010 0110100110011100 -37-14 105-100

29 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

30 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.

31 31 In binary we can find the negative of a number by using its two’s complement Therefore BinaryA – BinaryB  BinaryA + (two’s complement of BinaryB)

32 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 00000101 2

33 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)

34 34 Work in binary and find 23 - 11 So 23 - 11  00010111 + 11110101  100001100 Since we are working in 8 bits we discard the leftmost bit so the answer is 00001100 2

35 35 Perform the following using two’s complement arithmetic 1. 69 – 26 2. 14 – 5 3. 100 – 50 4. 77 – 33 5. 81 - 81

36 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.

37 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.

38 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

39 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 :-

40 40 I would then have fixed my decimal point to be always after the 2 nd 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?

41 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.

42 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?

43 43 What’s the largest number overall? 11111.111 2 But what is this in denary? To answer that we need to understand binary fractions

44 44 BINARY FRACTIONS Let us agree on the following about decimals in the denary system.npxyz  n / 10 1 + p / 10 2 + x / 10 3 + y / 10 4 + z / 10 5 …  n / 10 + p / 100 + x / 1000 + y / 10000 + z / 100000 …

45 45 BINARY FRACTIONS In the binary system therefore.npxyz  n / 2 1 + p / 2 2 + x / 2 3 + y / 2 4 + z / 2 5 …  n / 2 + p / 4 + x / 8 + y / 16 + z / 32 …

46 46 BINARY FRACTIONS Converting binary fractions to denary.01001  0 / 2 1 + 1 / 2 2 + 0 / 2 3 + 0 / 2 4 + 1 / 2 5  1 / 4 + 1 / 32 =>.28125

47 47 BINARY FRACTIONS In the binary system therefore.11001  1 / 2 1 + 1 / 2 2 + 0 / 2 3 + 0 / 2 4 + 1 / 2 5  1 / 2 + 1 / 4 + 1 / 32 =>.78125.

48 48 BINARY FRACTIONS In the binary system therefore.010111  0 / 2 1 + 1 / 2 2 + 0 / 2 3 + 1 / 2 4 + 1 / 2 5 + 1 / 2 6  1 / 4 + 1 / 16 + 1 / 32 + 1 / 64 =>.359375

49 49.1 ½.05.01 ¼.025.0011/8.125.00011/16.0625.000011/32.03125.0000011/64.015625 Binary Fractions Table

50 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.111 2 = 31.875 10

51 51 Assuming that the decimal point is fixed after the fourth position convert the following binary numbers to denary 1.000110002.00100100 1.5 2.25 3.101010104.01111110 10.625 7.875 5.100110016.11110000 9.5625 15.0

52 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 Smallest00000000.00000001 0.0039063

53 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?)

54 54 Convert.075 10 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.11 2

55 55 Convert.1036 10 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.00011 2

56 56 Convert.0625 10 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.0001 2

57 57 Convert to binary 1..0865 2..146 3..149 4..652 5..1725 6..365

58 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 Smallest00000000000.00001 0.03125

59 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 Smallest00000000000000.01 0.25

60 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.

61 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

62 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

63 63 For denary fractions we get down to 1/10 th 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.

64 64 Advantages of Fixed Point Notation Simple arithmetic Faster processing

65 65 Disadvantages of Fixed Point Notation Loss of precision Limited range of numbers can be represented

66 66 Questions ?

67 67 ~ The E N D ~


Download ppt "DATA REPRESENTATION Y. Colette Lemard February 2009 2."

Similar presentations


Ads by Google