Upload
valerie-gibson
View
230
Download
6
Embed Size (px)
Citation preview
NUMBER REPRESENTATIONCHAPTER 3 – part 3
ONE’S COMPLEMENT REPRESENTATION
CHAPTER 3 – part 3
Integer Representation
Integer Representat
ion
Unsigned Signed
Sign and Magnitude
One’s Complemen
t
Two’s Complemen
t
One’s complement integers
To represent
+ positive number same way as UNSIGNED Integer
- negative number complement the
positiveRANGE : -(2N-1 -1)…. +(2N-1 -1)
One’s complement integers
Table 3.5 Range of One’s complement integers
#of Bits ---------
81632
Range----------------------------------------------------
----127 -0 -32767 -0-2,147,483,647 -0
+0 +127
+ 0 +32767
+ 0 +2,147,483,647
One’s complement integers
There are two 0s in One’s complement
representation: positive and negative.
In an 8-bit allocation:+0 00000000
-0 10000000
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 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. bits4. 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,
00000111 . The sign is positive so no more action is
needed
Example 4
Solution
Store –258 in a 16-bit memory location using one’s complement representation
First change the number to binary 100000010.
Add 7 0s to make a total of N (16) bits, 0000000100000010.
The sign is Negative so each bit is complemented
0000000100000010 1111111011111101
Example 5
Solution
One’s complement integers
Table 3.6 Example of storing one’s complement integers in two computers
Decimal
------------+7−7
+124−124
+24,760−24,760
8-bit allocation
------------00000111111110000111110010000011overflowoverflow
16-bit allocation
------------------------------000000000000011111111111111110000000000001111100111111111000001101100000101110001001111101000111
One’s complement integers
Interpretation1. If the left most bit is 0 (positive number)
A. Change the entire number from binary to decimal
B. Put a positive sign(+) in front of the number
2. If the left most bit is 1 (negative number)
A. Complement the entire number (change all 0’s to 1’s and
vice versa)
B. Change the entire number from binary to decimal
C. Put a negative sign(-) in front of the number
Interpret 11110110 to decimal if the number was stored as a one’s complement integer.
the leftmost bit is 1, so the number is negative
Complement the number 11110110 00001001
the complement in decimal is 9
So the answer is -9
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
Integer Representat
ion
Unsigned Signed
Sign and Magnitude
One’s Complemen
t
Two’s Complemen
t
Two’s complement integers
It’s…The most commonThe most importantThe most widely used representation today
RANGE : -(2N-1)…. +(2N-1 -1)
Two’s complement integers
Table 3.7 Range of Two’s complement integers
#of Bits ---------
81632
Range----------------------------------------------------
----128 -0 -32768 -0-2,147,483,648 -0
+0 +127
+ 0 +32767
+ 0 +2,147,483,647
Two’s complement integers
There is Only one 0 in Two’s complement
representation
In an 8-bit allocation:0 00000000
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 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,
00000111 . The sign is positive so no more action is
needed
Example 4
Solution
Store –40in a 16-bit memory location using two’s complement representation
First change the number to binary 101000. Add 10 0s to make a total of N (16) bits,
0000000000101000. The sign is Negative so leave the rightmost
0’s up to the first 1
0000000000101000
1111111111011000
Example 5
Solution
Two’s complement integers
Table 3.8 Example of storing two’s complement integers in two computers
Decimal
------------+7−7
+124−124
+24,760−24,760
8-bit allocation
------------00000111111110010111110010000100overflowoverflow
16-bit allocation
------------------------------000000000000011111111111111110010000000001111100111111111000010001100000101110001001111101001000
Two’s complement integers
Interpretation1. If the left most bit is 0 (positive number)
A. Change the entire number from binary to decimal
B. Put a positive sign(+) in front of the number
2. If the left most bit is 1 (negative number)
A. leave the rightmost 0’s up to the the first 1 unchanged.
Complement the rest bits.
B. Change the whole number from binary to decimal
C. Put a negative sign(-) in front of the number
Interpret 11110110 to decimal if the number was stored as a two’s complement integer.
the leftmost bit is 1, so the number is negativeLeave 10 at the right alone and Complement the
rest11110110 00001010the complement in decimal is 10
So the answer is -10
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
Two’s compleme
nt
One’s compleme
nt
Sign & magnitude Unsigned Contents
of Memory
+0 +0 +0 0 0000
+1 +1 +1 1 0001
+2 +2 +2 2 0010
+3 +3 +3 3 0011
+4 +4 +4 4 0100
+5 +5 +5 5 0101
+6 +6 +6 6 0110
+7 +7 +7 7 0111
-8 -7 -0 8 1000
-7 -6 -1 9 1001
-6 -5 -2 10 1010
-5 -4 -3 11 1011
-4 -3 -4 12 1100
-3 -2 -5 13 1101
-2 -1 -6 14 1110
-1 -0 -7 15 1111
EXCESS SYSTEM
Excess System
It's another representation that allows you to store both �positive and negative numbers in a computer
� the magic number a positive number
used in the conversion process
� = 2N-1 -1 OR 2N-1
where N is the bit allocation�The bit allocation :is the number of bits used to represent an integer
Example
If N= 8 bits .Calculate the magic number.
Answer:
=2N-1 -1 OR 2N-1
=28-1 -1 OR 28-1
=127 OR 128 EXCESS_127 OR EXCESS_128
Excess System RepresentationTo 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 RepresentationExample:Represent –25 in Excess_127 using an 8-
bit allocation.
Answer:127 + (-25) = 102102 1100110add 0’s to the left to make it 8 bit01100110
Excess System InterpretationTo interpret a number in Excess, use the
following procedure: Change the number to decimal � Subtract the magic number from the
integer
Excess System InterpretationExample:Interpret 11111110 if the
representation is Excess_127.
Answer:11111110 254
254 – 127 = 127
FLOATING POINT REPRESENTATION
Floating point representation
Floating point number = a number containing an integer & a fraction
Example: 14.234Integ
erFractio
n
Convert from Floating point number to binary
1. Convert the integer part to binary2. Convert the fraction to binary�3. Put a decimal point between the two �
parts
Convert from Floating point number to binary
ExampleTransform 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
Convert from Floating point number to binary
ExampleTransform 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
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
Normaliazed Move Original Number
+ 26 x 1.01000111001 6
+ 1010001.11001
-2 2 x 1.110011 2
- 111.000011
+2-6 x 1.11001 6 + 0.00000111001
-2-3 x 1.110011 3 - 0.001110011
Normalization
After the number is normalized we store 3 pieces of information about it:
SIGN EXPONENT MANTISSA
Example:
+ 26 x 1.0001110101
SIGN EXPONENT
MANTISSA
IEEE standard for floating point representation
Single-Precesion RepresentationThe 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
EXAMPLE
Show the representation of the normalized number + 26 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
SIGN EXPONENT
MANTISSA
Example of floating point representation
Mantissa Exponent
Sign
Number
11000011000000000000000
10000001 1 -2 2 x 1.11000011
11001000000000000000000
01111001 0 +2-6 x 1.11001
11001100000000000000000
01111100 1 -2-3 x 1.110011
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 sign2. 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 decimal6. Change the fraction part to decimal7. Combine the whole and the fraction parts
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