NUMBER REPRESENTATION CHAPTER 3 – part 3
ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3
Integer Representation UnsignedSigned Sign and Magnitude One’s Complement Two’s Complement
One’s complement integers
Table 3.5 Range of One’s complement integers # of Bits # of Bits Range 127 0 0 ,147,483,647
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 There are two 0s in There are two 0s in One’s complement representation: positive and negative. In an 8-bit allocation: +0
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
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
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, The sign is positive so no more action is needed Example 4 Solution
Example 5 Solution
One’s complement integers Table 3.6 Example of storing one’s complement integers in two computers Decimal Decimal − − ,760 −24,760 8-bit allocation overflow 16-bit allocation
One’s complement integers
Example 6 Solution
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
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
TWO’S COMPLEMENT REPRESENTATION
Integer Representation UnsignedSigned Sign and Magnitude One’s Complement Two’s Complement
Two’s complement integers It’s… The most common The most important The most widely used representation today
Two’s complement integers Table 3.7 Range of Two’s complement integers # of Bits # of Bits Range 128 0 0 ,147,483,647
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 There is Only one 0 in There is Only one 0 in Two’s complementrepresentation In an 8-bit allocation: 0
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
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.
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, The sign is positive so no more action is needed Example 4 Solution
Example 5 Solution
Two’s complement integers Table 3.8 Example of storing two’s complement integers in two computers Decimal Decimal − − ,760 −24,760 8-bit allocation overflow 16-bit allocation
Two’s complement integers
Example 6 Solution
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
SUMMARY OF INTEGER REPRESENTATION Unsigned Sign & magnitude One’s complement Two’s complement
One’s complement Sign & magnitude Unsigned Contents of Memory
EXCESS SYSTEM
Excess System
Example
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
Excess System Representation
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
Excess System Interpretation
FLOATING POINT REPRESENTATION
Floating point representation Floating point number = a number containing an integer & a fraction Example: IntegerFraction
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
Convert from Floating point number to binary Example Transform the fraction 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 1.50 1.0
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
NORMALIZATION
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.
Normalization NormaliazedMoveOriginal Number x x x x
Normalization After the number is normalized we store 3 pieces of information about it: SIGN EXPONENT MANTISSA Example : x SIGNEXPONENTMANTISSA
IEEE standard for floating point representation
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_ Store the mantissa as unsigned integer
EXAMPLE Show the representation of the normalized number x 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: SIGNEXPONENTMANTISSA
Example of floating point representation MantissaExponentSignNumber x x x
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
Example Interpret the following 32-bit floating-point number ANSWER : The sign is negative. The exponent is –3 (124 –127). The number after normalization is x