Ch01P3 Integer Representation
Ch01P3 Integer Representation
Representation
Figure 3-5
Range of integers
Figure 3-6
Taxonomy of integers
Table 3.1 Range of unsigned integers
#---------
of Bits
Range
-------------------------
816
------------
0255
0535
65,
Example 3
Store 7 in an 8-bit memory location.
Solution
First change the number to binary 111. Add
five 0s to make a total of N (8) bits,
00000111. The number is stored in the
memory location.
Example 4
Store 258 in a 16-bit memory location.
Solution
First change the number to binary
100000010. Add seven 0s to make a total of
N (16) bits, 0000000100000010. The
number is stored in the memory location.
Table 3.2 Example of storing unsigned integers in
two different computers
Decimal 8-bit allocation
16-bit allocation
-------- ------------
---------------------
---- 00000111
---------
7
11101010
overflow
0000000000000111
0000000011101010
234
258
overflow
0000000100000010
24,760
overflow
0110000010111000
overflow
1,245,67
8
Example 5
Interpret 00101011 in decimal if the
number was stored as an unsigned
integer.
Solution
Using the procedure shown in
Figure 3.3 , the number in decimal
is 43.
Table 3.3 Range of sign-and-magnitude integers
#--------
of Bits -------------------------------------
Range
--8
127 ------------------
+0
16 0
+127
+0
32767
32
0
+32767
0
+0
+2,147,483,647
Note:
In sign-and-magnitude
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.
Note:
There are two 0s in sign-and-
magnitude
representation: positive and negative.
In an 8-bit allocation:
+0 00000000
-0 10000000
Example 6
Store +7 in an 8-bit memory location
using sign-and-magnitude
representation.
Solution
First change the number to binary 111. Add
four 0s to make a total of N-1 (7) bits,
0000111. Add an extra zero because the
number is positive. The result is:
00000111
Example 7
Store –258 in a 16-bit memory
location using sign-and-magnitude
representation.
Solution
First change the number to binary
100000010. Add six 0s to make a total of N
-1 (15) bits, 000000100000010. Add an
extra 1 because the number is negative.
The result is:
1000000100000010
Table 3.4 Example of storing sign-and-magnitude integ
in two computers
#--------
of Bits -------------------------------------
Range
-8
127 ------------------
+0
+127
0
16
32
0
32767 +0
+32767
0
+0
+2,147,483,647
Note:
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.
Example 9
Store +7 in an 8-bit memory location
using one’s complement
representation.
Solution
First change the number to binary 111. Add
five 0s to make a total of N (8) bits,
00000111. The sign is positive, so no more
action is needed. The result is:
00000111
Example 10
Store –258 in a 16-bit memory
location using one’s complement
representation.
Solution
First change the number to binary
100000010. Add seven 0s to make a total of
N (16) bits, 0000000100000010. The sign is
negative, so each bit is complemented. The
result is:
1111111011111101
Table 3.6 Example of storing one’s complement integer
two different computers
#--------
of Bits
-------------------------------------
Range
-8
128 ------------------
0
+1
32,768
27
16
32
0 +32,7
67
047
+2,147,483,6
Note:
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.
Example 12
Store +7 in an 8-bit memory location
using two’s complement representation.
Solution
First change the number to binary 111. Add
five 0s to make a total of N (8) bits,
00000111.The sign is positive, so no more
action is needed. The result is:
00000111
Example 13
Store –40 in a 16-bit memory location using
two’s complement representation.
Solution
First change the number to binary 101000.
Add ten 0s to make a total of N (16) bits,
0000000000101000. The sign is negative,
so leave the rightmost 0s up to the first 1
(including the 1) unchanged and
complement the rest. The result is:
1111111111011000
Table 3.8 Example of storing two’s complement integer
two different computers
Number Sign
---- Exponent
----------
Mantissa
-2 ------------
2 x 1.11000011
10
10000001
-
-------------------------
------
+2 -6 x 1.11001
-2-3 x 1.110011
1
01111001
11000011000000000000000
11001000000000000000000
01111100
11001100000000000000000
Example 20
Interpret the following 32-bit floating-
point number
1 01111100
11001100000000000000000
Solution