Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Brooks/Cole, 2003 Chapter 3 Number Representation.

Similar presentations


Presentation on theme: "©Brooks/Cole, 2003 Chapter 3 Number Representation."— Presentation transcript:

1 ©Brooks/Cole, 2003 Chapter 3 Number Representation

2 ©Brooks/Cole, 2003 It is not efficient to represent numbers in the same way as symbols representation. For example representing 67854 as symbols using ASCII requires 5 bytes each representing a digit. And it is obvious That as the number of digits increases the number of bytes Increases. Therefore we need a more efficient way to represent numbers. Number representation

3 ©Brooks/Cole, 2003 DECIMALANDBINARYDECIMALANDBINARY 3.1

4 Figure 3-1 Decimal system

5 ©Brooks/Cole, 2003 Figure 3-2 Binary system

6 ©Brooks/Cole, 2003 CONVERSIONCONVERSION 3.2

7 Figure 3-3 Binary to decimal conversion

8 ©Brooks/Cole, 2003 Figure 3-4 Decimal to binary conversion

9 ©Brooks/Cole, 2003 INTEGERREPRESENTATIONINTEGERREPRESENTATION 3.4

10 Figure 3-5 Range of integers Integers are whole numbers without a fraction. For example,134 is an integer but 134.987 is not. Integers can be positive and negative.

11 ©Brooks/Cole, 2003 Figure 3-6 Taxonomy of integers

12 ©Brooks/Cole, 2003 Unsigned integers # of Bits # of Bits --------- 8 16 Range Range ------------------------------------- 0 255 0 65,535 The maximum unsigned integer depends on the number of bits allocated in the computer to store an unsigned integer. For N number of bits, the maximum integer to be represented is (2 N -1)

13 ©Brooks/Cole, 2003 Table 3.2 Example of storing unsigned integers in two different computers two different computers Decimal Decimal ------------ 7 234 258 24,760 1,245,678 8-bit allocation ------------ 00000111 11101010 overflow 16-bit allocation ------------------------------ 0000000000000111 0000000011101010 0000000100000010 0110000010111000 overflow

14 ©Brooks/Cole, 2003 Applications (unsigned) Counting Addressing

15 ©Brooks/Cole, 2003 Signed integer: 1.Sign and magnitude In this format one bit is needed to represent the sign of integer number (0 for positive integer and 1 for negative) For N number of bits allocated for the signed number, the range of integer numbers is given by: -(2 N-1 – 1) …… (2 N-1 -1)

16 ©Brooks/Cole, 2003 Sign-and-magnitude integers # of Bits # of Bits ---------- 8 16 32  127  0  32767  0   0 +0 +127 +0 +32767 +0 +2,147,483,647 Range-------------------------------------------------------

17 ©Brooks/Cole, 2003 Sign and Magnitude Representation 1.Convert the magnitude to binary 2.Add 0s to the left to make the total number of bits N-1. 3.If number is positive add 0 to the left; if number is negative add 1 to the left

18 ©Brooks/Cole, 2003 Table 3.4 Example of storing sign-and-magnitude integers in two computers Decimal Decimal ------------ +7 -124 +258 -24,760 8-bit allocation ------------ 00000111 11111100 overflow 16-bit allocation ------------------------------ 0000000000000111 1000000001111100 0000000100000010 1110000010111000

19 ©Brooks/Cole, 2003 Sign and Magnitude Interpertation 1.Ignore the first (liftmost) bit, 2.Change the following bits to decimal. 3.Attach + or – sign based on the left most bit.

20 ©Brooks/Cole, 2003 Advantages, Disadvantages, and Application (sign and magnitude) 1.Disadvantages: two zeros 2.Advantages: easy transformation 3.Application: data communication.

21 ©Brooks/Cole, 2003 Signed integer: 2. One’s Complement In this format the negative number is the complement of the positive number, for example -7 is represented as the binary complement of +7. The number’s complement is obtained by changing all 0s to 1s and all 1s to 0s. The left most digit is assigned for the number’s sign (0 for positive, 1 for negative).

22 ©Brooks/Cole, 2003 Range of one’s complement integers # of Bits # of Bits --------- 8 16 32  127  0  32767  0   0 +0 +127 +0 +32767 +0 +2,147,483,647 Range------------------------------------------------------- For N number of bits allocated for the signed number, the range of integer numbers is given by: -(2 N-1 – 1) …… (2 N-1 -1)

23 ©Brooks/Cole, 2003 One’s Complements Representation 1.Convert the magnitude to binary 2.If number is positive, add 0s to the left to make the total number of bits N. 3.If number is negative add complement the positive representation (step 2)

24 ©Brooks/Cole, 2003 Table 3.6 Example of storing one’s complement integers in two different computers Decimal Decimal ------------       8-bit allocation ------------ 00000111 11111000 01111100 10000011 overflow 16-bit allocation ------------------------------ 0000000000000111 1111111111111000 0000000001111100 1111111110000011 0110000010111000 1001111101000111

25 ©Brooks/Cole, 2003 One’s Complement Interpretation If the leftmost 0 (positive number) 1.Change the entire number to decimal 2.Put (+) in front of the number. If the leftmost is 1 (negative number) 1.Complement the entire number. 2.Change the entire number to decimal. 3.Put (-) in front of the number

26 ©Brooks/Cole, 2003 Disadvantages, and Application (One’s Complement) 1.Disadvantages: two zeros 2.Application: error detection and correction.

27 ©Brooks/Cole, 2003 Signed integer: 3. Two’s Complement Two’s complement solves the problems of two zeros. Two’s complement is widely used representation of integers today. For N number of bits allocated for the signed number, the range of integer numbers is given by: -(2 N-1 ) …… (2 N-1 -1) The left most digit shows the number’s sign (0 for positive, 1 for negative).

28 ©Brooks/Cole, 2003 Range of two’s complement integers # of Bits --------- 8 16 32  128  32,768  0 +127 0 +32,767 0 +2,147,483,647 Range-------------------------------------------------------

29 ©Brooks/Cole, 2003 Two’s Complements Representation 1.Convert the magnitude to binary 2.Add 0s to the left to make the total number of bits equal to N. 3.If the number is positive no action is needed. If the number is negative, complement after the first 1 from the right of the positive representation.

30 ©Brooks/Cole, 2003 Table 3.8 Example of storing two’s complement integers in two different computers Decimal Decimal ------------       8-bit allocation ------------ 00000111 11111001 01111100 10000100 overflow 16-bit allocation ------------------------------ 0000000000000111 1111111111111001 0000000001111100 1111111110000100 0110000010111000 1001111101001000

31 ©Brooks/Cole, 2003 Two’s Complement Interpretation If the leftmost 0 (positive number) 1.Change the entire number to decimal 2.Put (+) in front of the number. If the leftmost is 1 (negative number) 1.Complement after the first 1 from the right. 2.Change the entire number to decimal. 3.Put (-) in front of the number

32 ©Brooks/Cole, 2003 Two’s complement can be achieved by reversing all bits except the rightmost bits up to the first 1 (inclusive). If you two’s complement a positive number, you get the corresponding negative number. If you two’s complement a negative number, you get the corresponding positive number. If you two’s complement a number twice, you get the original number. Note:

33 ©Brooks/Cole, 2003 Application (Tow’s Complement) Two’s complement is used in today’s computer

34 ©Brooks/Cole, 2003 Table 3.9 Summary of integer representation Contents of Memory Contents of Memory ------------ 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Unsigned------------0123456789101112131415 Sign-and- Magnitude  One’s Complement  Two’s Complement 

35 ©Brooks/Cole, 2003 Signed integer: Excess System Excess system is used to store signed integer numbers in computer. In Excess system a positive number called magic number is used for this format. The magic number is either 2 N-1 or 2 N-1 -1. For example if N = 8 the magic number is either 128 (called excess_128) or 127 (called excess_127)

36 ©Brooks/Cole, 2003 Excess System Representation 1.Add the magic number to the integer. 2.Change the result to binary 3.Add 0s to the left to make total number of bits equal to N.

37 ©Brooks/Cole, 2003 Excess System Interpretation 1.Change the number to decimal 2.Subtract the magic number form the integer.

38 ©Brooks/Cole, 2003 Excess System Range 1.For Magic number equal to 2 N-1 the range is - (2 N-1 )….. +(2 N-1 -1) # of Bits --------- 8 16 32  128  32,768  0 +127 0 +32,767 0 +2,147,483,647 Range-------------------------------------------------------

39 ©Brooks/Cole, 2003 Excess System Range 1.For Magic number equal to 2 N-1 -1 the range is - (2 N-1 -1)….. +(2 N-1 ) # of Bits --------- 8 16 32  127  32,767  0 +128 0 +32,768 0 +2,147,483,648 Range-------------------------------------------------------

40 ©Brooks/Cole, 2003 Advantages, Disadvantages and Application (Excess System) Advantages: Easy transformation. Disadvantages: operation on excess system is very complicated. Applications: used in storing exponential values of fraction.

41 ©Brooks/Cole, 2003 FLOATING-POINTREPRESENTATIONFLOATING-POINTREPRESENTATION

42 Floating Point Number Floating point number is a number containing an integer and a fraction For example in floating point number 21.345, the integer part is 21 and the fraction is 0.345

43 ©Brooks/Cole, 2003 Floating Point Representation 1.Convert the integer part to binary 2.Convert the fraction part to binary by repetitively multiply the fraction part by 2. The binary digit is the integer part of the result of multiplication. Stop whenever the fraction part becomes 0 or when you reach the maximum number of bits you can use. 3.Put a decimal point between the two parts.

44 ©Brooks/Cole, 2003 Figure 3-7 Changing fractions to binary

45 ©Brooks/Cole, 2003 Floating Point Interpretation 1.Convert the integer part to decimal 2.Convert the fraction part to decimal by: 1. multiplying each digit by its weight. 2.Add alltogether 3.Put a decimal point between the two parts.

46 ©Brooks/Cole, 2003 Figure 3-3 Binary floating to decimal conversion. 0 2 -1 2 -2 2 -3 2 -4 2 -5 2 -6 2 -7 0 + 0.25 + 0 + 0.0625 + 0.03125 +0 +0.0078125 0.3515625

47 ©Brooks/Cole, 2003 Normalization Normalization is a standard way to write floating point binary number. Normalization is achieved by moving the decimal point so that there is only one 1 to the left of it. To indicate how many digits the decimal point has moved, multiply the number by 2 e which indicates the direction and number of digits moved. If : –e is positive, decimal point moved to the left –e is negative, decimal point moved to the right

48 ©Brooks/Cole, 2003 Table 3.10 Example of normalization Original Number Original Number ------------ +1010001.1101 -111.000011 +0.00000111001 -001110011 Move Move ------------  6  2 6  3  Original Number Original Number ------------     Normalized ------------    x     x    x     x 

49 ©Brooks/Cole, 2003 Sign, Exponent and Mantissa After the number normalization you store only three pieces of information about the number: sign, exponent and mantissa. –Sign is the number sign (stored in 1 bit) –Exponent (power of 2) shows direction and magnitude of decimal point movement. –Mantissa is the bits to the right of the decimal point.

50 ©Brooks/Cole, 2003 Normalization (example) For the number: + 1000111.0101 Normalized Number: + 2 6 x 1.0001110101 Sign: + Exponent: 6 Mantissa: 0001110101

51 ©Brooks/Cole, 2003 Figure 3-8 IEEE standards for floating-point representation

52 ©Brooks/Cole, 2003 Single Precision Representation Store the sign as 0 (positive) or 1 (negative) Store the exponent (power of 2) as Excess_127 Store the mantissa as an unsigned integer. Add 0s to the right of the mantissa to make the total number of mantissa bits equal to 23

53 ©Brooks/Cole, 2003 Table 3.11 Example of floating-point representation Sign Sign ---- 1 0 1 Mantissa ------------------------------- 11000011000000000000000 11001000000000000000000 11001100000000000000000 Number ------------ -2 2 x 1.11000011 +2 -6 x 1.11001 -2 -3 x 1.110011 Exponent Exponent ----------- 10000001 01111001 01111100

54 ©Brooks/Cole, 2003 Floating point Interpretation (Single Precision) The sign is the leftmost bit Change the next 8 bits to decimal and subtract 127 from it. add 1 to the left of the mantissa (next 23 bits) and discard the zeros to the left of it. Move the decimal point to its original position. Convert the integer and fraction to decimal

55 ©Brooks/Cole, 2003 Hexadecimal Notation Floating point numbers can be written using hexadecimal notation. For example : 81.125, using IEEE standards is 01000010101000111001000000000000 And in Hexadecimal notation: x42A39000


Download ppt "©Brooks/Cole, 2003 Chapter 3 Number Representation."

Similar presentations


Ads by Google