1 / 67

DATA REPRESENTATION

DATA REPRESENTATION. 2. Y. Colette Lemard. February 2009. TYPES OF NUMBER REPRESENTATION. There are two major classes of number representation :- FIXED POINT FLOATING POINT. FIXED POINT SYSTEMS. Most of us are familiar with fixed representation to some extent

micah
Télécharger la présentation

DATA REPRESENTATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DATA REPRESENTATION 2 Y. Colette Lemard February 2009

  2. TYPES OF NUMBER REPRESENTATION

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

  4. FIXED POINT SYSTEMS

  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. BINARY CODED DECIMAL

  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

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

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

  10. SIGNED MAGNITUDE

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

  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. ONE’S COMPLEMENT

  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. The one’s complement of a number is a form of the negative of the number.

  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. TWO’S COMPLEMENT

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

  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. 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. 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. 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. Finding the Two’s Complement of a Denary Number • Find the two’s complement of • 47 63 • 81 25 • 11010001 11000001 • 10101111 11100111

  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. 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. Converting to denary from two’s complement • Flip the bits then add 1

  28. What denary numbers are these? • 11011011 11110010 • 01101001 10011100 • -37 -14 • 105 -100

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

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

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

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

  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. 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. What’s the largest number overall? 11111.1112 But what is this in denary? To answer that we need to understand binary fractions

  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 …

  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 …

  46. BINARY FRACTIONS • Converting binary fractions to denary .01001 • 0/21 + 1/22 + 0/23 + 0/24 + 1/25 • 1/4 + 1/32 => .28125

  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.

  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

  49. Binary Fractions Table

  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

More Related