Download presentation
Presentation is loading. Please wait.
Published byValerie Gibson Modified over 9 years ago
1
NUMBER REPRESENTATION CHAPTER 3 – part 3
2
ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3
3
Integer Representation UnsignedSigned Sign and Magnitude One’s Complement Two’s Complement
4
One’s complement integers
5
Table 3.5 Range of One’s complement integers # of Bits # of Bits --------- 8 16 32 Range------------------------------------------------------- 127 0 32767 0 0 +0 +127 +0 +32767 +0 +2,147,483,647
6
One’s complement integers There are two 0s in There are two 0s in One’s complement representation: positive and negative. In an 8-bit allocation: +0 00000000 -0 10000000 There are two 0s in There are two 0s in One’s complement representation: positive and negative. In an 8-bit allocation: +0 00000000 -0 10000000
7
One’s complement integers In one’’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 0, the number is positive. If it is 1, the number is negative In one’’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 0, the number is positive. If it is 1, the number is negative
8
One’s complement integers Storing One’s complement integer process: 1. The integer is changed to binary, (the sign is ignored). 2. 0s are added to the left of the number to make a total of N 3. bits 4. If the sign is positive, no more action is needed. If the sign is negative, every bit is complemented
9
Store +7 in an 8-bit memory location using one’s complement representation. The integer is changed to binary (111). Add 5 0s to make a total of N (8) bits, 00000111. The sign is positive so no more action is needed Example 4 Solution
10
Example 5 Solution
11
One’s complement integers Table 3.6 Example of storing one’s complement integers in two computers Decimal Decimal ------------ +7 −7 +124 −124 +24,760 −24,760 8-bit allocation ------------ 00000111 11111000 01111100 10000011 overflow 16-bit allocation ------------------------------ 0000000000000111 1111111111111000 0000000001111100 1111111110000011 0110000010111000 1001111101000111
12
One’s complement integers
13
Example 6 Solution
14
The one’s complement representation is not used now by computers because: Operations: such as subtraction and addition is not straightforward for this representation. Uncomfortable in programming: because there are two 0s in this representation One’s complement Applications
15
However.. The advantage of this representation is: 1. It’s the foundation of the next representation(Two’s complement) 2. It has properties that make it interesting for data communication applications such as error detection and correction One’s complement Applications
16
TWO’S COMPLEMENT REPRESENTATION
17
Integer Representation UnsignedSigned Sign and Magnitude One’s Complement Two’s Complement
18
Two’s complement integers It’s… The most common The most important The most widely used representation today
19
Two’s complement integers Table 3.7 Range of Two’s complement integers # of Bits # of Bits --------- 8 16 32 Range------------------------------------------------------- 128 0 32768 0 0 +0 +127 +0 +32767 +0 +2,147,483,647
20
Two’s complement integers There is Only one 0 in There is Only one 0 in Two’s complementrepresentation In an 8-bit allocation: 0 00000000 There is Only one 0 in There is Only one 0 in Two’s complementrepresentation In an 8-bit allocation: 0 00000000
21
Two’s complement integers In two’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 0, the number is positive. If it is 1, the number is negative In two’s complement representation, the leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 0, the number is positive. If it is 1, the number is negative
22
Two’s complement integers Storing One’s complement integer process: 1. The number is changed to binary, (the sign is ignored). 2. 0s are added to the left of the number to make a total of N bits 3. If the sign is positive, no more action is needed. If the sign is negative, leave all the rightmost 0’s and the first 1 unchanged. Then complement the rest of the bits.
23
Store +7 in an 8-bit memory location using two’s complement representation. The integer is changed to binary (111). Add 5 0s to make a total of N (8) bits, 00000111. The sign is positive so no more action is needed Example 4 Solution
24
Example 5 Solution
25
Two’s complement integers Table 3.8 Example of storing two’s complement integers in two computers Decimal Decimal ------------ +7 −7 +124 −124 +24,760 −24,760 8-bit allocation ------------ 00000111 11111001 01111100 10000100 overflow 16-bit allocation ------------------------------ 0000000000000111 1111111111111001 0000000001111100 1111111110000100 0110000010111000 1001111101001000
26
Two’s complement integers
27
Example 6 Solution
28
The two’s complement representation is the standard representation used for storing integers by computers today because it makes the operations simple. Two’s complement Applications
29
SUMMARY OF INTEGER REPRESENTATION Unsigned Sign & magnitude One’s complement Two’s complement
30
One’s complement Sign & magnitude Unsigned Contents of Memory +0 00000 +1 10001 +2 20010 +3 30011 +4 40100 +5 50101 +6 60110 +7 70111 -8-7-081000 -7-691001 -6-5-2101010 -5-4-3111011 -4-3-4121100 -3-2-5131101 -2-6141110 -0-7151111
31
EXCESS SYSTEM
32
Excess System
33
Example
34
Excess System Representation To represent a number in Excess, use the following procedure: Add the magic number to the integer Change the result to binary and add 0s so that there is a total of N bits
35
Excess System Representation
36
Excess System Interpretation To interpret a number in Excess, use the following procedure: Change the number to decimal Subtract the magic number from the integer
37
Excess System Interpretation
38
FLOATING POINT REPRESENTATION
39
Floating point representation Floating point number = a number containing an integer & a fraction Example: 14.234 IntegerFraction
40
Convert from Floating point number to binary 1. Convert the integer part to binary 2. Convert the fraction to binary 3. Put a decimal point between the two parts
41
Convert from Floating point number to binary Example Transform the fraction 0.875 to binary Answer: Write the fraction at the left corner. Multiply the number continuously by 2 and extract the integer part as the binary digit. Stop when the number is 0.0. fraction binary 0.875 1.750 1.50 1.0 0.0 0. 1 1 1
42
Convert from Floating point number to binary Example Transform the fraction 0.4 to a binary of 6 bits. Answer: Write the fraction at the left cornet. Multiply the number continuously by 2 and extract the integer part as the binary digit. You can never get the exact binary representation. Stop when you have 6 bits fraction binary 0.4 0.8 1.6 1.2 0.4 0.8 1.6 0. 0 1 1 0 0 1
43
NORMALIZATION
44
Normalization A fraction is normalized so that operations are simpler Normalization: the moving of the decimal point so that there is only one 1 to the left of the decimal point.
45
Normalization NormaliazedMoveOriginal Number + 2 6 x 1.01000111001 6+ 1010001.11001 -2 2 x 1.110011 2- 111.000011 +2 -6 x 1.110016+ 0.00000111001 -2 -3 x 1.1100113- 0.001110011
46
Normalization After the number is normalized we store 3 pieces of information about it: SIGN EXPONENT MANTISSA Example : + 2 6 x 1.0001110101 SIGNEXPONENTMANTISSA
47
IEEE standard for floating point representation
48
Single-Precesion Representation The procedure of storing a normalized floating point number using single precession format is as follow: 1. Store the sign as 0 (positive) or 1 (negative) 2. Store the exponent (power of 2) as Excess_127 3. Store the mantissa as unsigned integer
49
EXAMPLE Show the representation of the normalized number + 2 6 x 1.01000111001 ANSWER: The sign is positive. The Excess_127 representation of the exponent is 133. You add extra 0s on the right to make it 23 bits. The number in memory is stored as: 0 10000101 01000111001000000000000 SIGNEXPONENTMANTISSA
50
Example of floating point representation MantissaExponentSignNumber 11000011000000000000000100000011-2 2 x 1.11000011 11001000000000000000000011110010+2 -6 x 1.11001 11001100000000000000000011111001-2 -3 x 1.110011
51
Floating point Interpretation for single precision the following procedure interprets a 32-bit floating-point number stored in memory 1. Use the leftmost bit as the sign 2. Change the next 8 bit to decimal and subtract 127 from it. (this is the exponent) 3. Add 1 and a decimal point to the next 23 bits (ignore any extra 0’s in the right) 4. Move the decimal point to the correct position using the value of the exponent 5. Change the whole part to decimal 6. Change the fraction part to decimal 7. Combine the whole and the fraction parts
52
Example Interpret the following 32-bit floating-point number 1 01111100 11001100000000000000000 ANSWER : The sign is negative. The exponent is –3 (124 –127). The number after normalization is - 2 -3 x 1.110011
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.