Escolar Documentos
Profissional Documentos
Cultura Documentos
Number
Representation
OBJECTIVES
After reading this chapter, the reader should
be able to :
Convert a number from decimal to binary notation and
vice versa.
Understand the different representations of an integer inside
a computer: unsigned, sign-and-magnitude, ones complement,
and twos complement.
Understand the Excess system that is used to store the
exponential part of a floating-point number.
Understand how floating numbers are stored inside a computer
using the exponent and the mantissa.
3.1
DECIMAL
AND
BINARY
Figure 3-1
Decimal system
Figure 3-2
Binary system
3.2
CONVERSION
Figure 3-3
Example 1
Convertthebinarynumber10011todecimal.
Solution
Write out the bits and their weights. Multiply the bit by
its corresponding weight and record the result. At the
end, add the results to get the decimal number.
Binary
Weights
1
16
0
8
0
4
1
2
1
1
Decimal
------------------------------------16 + 0 + 0 + 2 + 1
19
Example 2
Convertthedecimalnumber35tobinary.
Solution
Write out the number at the right corner. Divide the
number continuously by 2 and write the quotient and the
remainder. The quotients move to the left, and the
remainder is recorded under each quotient. Stop when the
quotient is zero.
0 1 2 4 8 17 35 Dec.
Binary
Figure 3-4
Figure 3-7
Example 17
Transformthefraction0.875tobinary
Solution
Writethefractionattheleftcorner.Multiplythe
numbercontinuouslyby2andextractthe
integerpartasthebinarydigit.Stopwhenthe
numberis0.0.
0.875 1.750 1.5 1.0 0.0
0
Example 18
Transformthefraction0.4toabinaryof6bits.
Solution
Writethefractionattheleftcornet.Multiplythe
numbercontinuouslyby2andextractthe
integerpartasthebinarydigit.Youcannever
gettheexactbinaryrepresentation.Stopwhen
youhave6bits.
0.4 0.8 1.6 1.2 0.4 0.8 1.6
0
3.4
INTEGER
REPRESENTATION
Figure 3-5
Range of integers
Figure 3-6
Taxonomy of integers
# of Bits
--------8
16
Range
------------------------------------0
255
0
65,535
Example 3
Store7inan8bitmemorylocation.
Solution
Firstchangethenumbertobinary111.Addfive
0stomakeatotalofN(8)bits,00000111.The
numberisstoredinthememorylocation.
Example 4
Store258ina16bitmemorylocation.
Solution
Firstchangethenumbertobinary100000010.
Addseven0stomakeatotalofN(16)bits,
0000000100000010.Thenumberisstoredinthe
memorylocation.
-----------7
234
258
24,760
1,245,678
8-bit allocation
-----------00000111
11101010
overflow
overflow
overflow
16-bit allocation
-----------------------------0000000000000111
0000000011101010
0000000100000010
0110000010111000
overflow
Example 5
Interpret00101011indecimalifthenumber
wasstoredasanunsignedinteger.
Solution
UsingtheprocedureshowninFigure
3.3,thenumberindecimalis43.
# of Bits
---------8
16
32
Range
------------------------------------------------------127
0 +0
+127
32767
0 +0
+32767
0 +0
+2,147,483,647
Note:
Insignandmagnituderepresentation,
theleftmostbitdefinesthesignofthe
number.Ifitis0,thenumberis
positive.Ifitis1,thenumberisnegative.
Note:
There are two 0s in sign-andmagnitude
representation: positive and
negative.
In an 8-bit allocation:
+0 00000000
-0 10000000
Example 6
Store+7inan8bitmemorylocationusing
signandmagnituderepresentation.
Solution
Firstchangethenumbertobinary111.Add
four0stomakeatotalofN1(7)bits,0000111.
Addanextrazerobecausethenumberis
positive.Theresultis:
00000111
Example 7
Store258ina16bitmemorylocation
usingsignandmagnituderepresentation.
Solution
Firstchangethenumbertobinary100000010.
Addsix0stomakeatotalofN1(15)bits,
000000100000010.Addanextra1becausethe
numberisnegative.Theresultis:
1000000100000010
Decimal
-----------+7
-124
+258
-24,760
8-bit allocation
-----------00000111
11111100
overflow
overflow
16-bit allocation
-----------------------------0000000000000111
1000000001111100
0000000100000010
1110000010111000
Example 8
Interpret10111011indecimalifthenumber
wasstoredasasignandmagnitudeinteger.
Solution
Ignoringtheleftmostbit,theremainingbitsare
0111011.Thisnumberindecimalis59.The
leftmostbitis1,sothenumberis59.
Note:
There are two 0s in ones
complement
representation: positive and
negative.
In an 8-bit allocation:
+0 00000000
-0 11111111
Ones complement
( )
If the sign is positive (0), no more action is
needed;
If the sign is negative, every bit is
complemented.
# of Bits
--------8
16
32
Range
------------------------------------------------------127
0 +0
+127
32767
0 +0
+32767
0 +0
+2,147,483,647
Note:
Inonescomplementrepresentation,
theleftmostbitdefinesthesignofthe
number.Ifitis0,thenumberis
positive.Ifitis1,thenumberisnegative.
Example 9
Store+7inan8bitmemorylocationusing
onescomplementrepresentation.
Solution
Firstchangethenumbertobinary111.Addfive
0stomakeatotalofN(8)bits,00000111.The
signispositive,sonomoreactionisneeded.The
resultis:
00000111
Example 10
Store258ina16bitmemorylocation
usingonescomplementrepresentation.
Solution
Firstchangethenumbertobinary100000010.
Addseven0stomakeatotalofN(16)bits,
0000000100000010.Thesignisnegative,so
eachbitiscomplemented.Theresultis:
1111111011111101
Decimal
-----------
8-bit allocation
-----------00000111
11111000
01111100
10000011
overflow
overflow
16-bit allocation
-----------------------------0000000000000111
1111111111111000
0000000001111100
1111111110000011
0110000010111000
1001111101000111
Example 11
Interpret11110110indecimalifthenumber
wasstoredasaonescomplementinteger.
Solution
Theleftmostbitis1,sothenumberisnegative.
Firstcomplementit.Theresultis00001001.
Thecomplementindecimalis9.Sotheoriginal
numberwas9.Notethatcomplementofa
complementistheoriginalnumber.
Note:
Onescomplementmeansreversingall
bits.Ifyouonescomplementapositive
number,yougetthecorresponding
negativenumber.Ifyouones
complementanegativenumber,youget
thecorrespondingpositivenumber.If
youonescomplementanumbertwice,
yougettheoriginalnumber.
Note:
Twoscomplementisthemostcommon,
themostimportant,andthemostwidely
usedrepresentationofintegerstoday.
Twos complement
If the sign is positive, no further action is
needed;
If the sign is negative, leave all the rightmost
0s and the first 1 unchanged. Complement the
rest of the bits
e.g. 0000000000101000
1111111111011000
Twos complement
0000000000101000
1111111111011000
1. 0000000000101000
2. 216-0000000000101000
Ones complement
1111111111010111
+1
1111111111011000
10000000000000000
-) 0000000000101000
1111111111011000
# of Bits
--------8
16
32
Range
------------------------------------------------------128
0
+127
32,768
0
+32,767
0
+2,147,483,647
Note:
Intwoscomplementrepresentation,
theleftmostbitdefinesthesignofthe
number.Ifitis0,thenumberispositive.
Ifitis1,thenumberisnegative.
Example 12
Store+7inan8bitmemorylocationusing
twoscomplementrepresentation.
Solution
Firstchangethenumbertobinary111.Addfive
0stomakeatotalofN(8)bits,00000111.The
signispositive,sonomoreactionisneeded.The
resultis:
00000111
Example 13
Store40ina16bitmemorylocationusingtwos
complementrepresentation.
Solution
Firstchangethenumbertobinary101000.Add
ten0stomakeatotalofN(16)bits,
0000000000101000.Thesignisnegative,so
leavetherightmost0suptothefirst1(including
the1)unchangedandcomplementtherest.The
resultis:
1111111111011000
Decimal
-----------
8-bit allocation
-----------00000111
11111001
01111100
10000100
overflow
overflow
16-bit allocation
-----------------------------0000000000000111
1111111111111001
0000000001111100
1111111110000100
0110000010111000
1001111101001000
Note:
There is only one 0 in twos
complement:
In an 8-bit allocation:
0 00000000
Example 14
Interpret11110110indecimalifthenumber
wasstoredasatwoscomplementinteger.
Solution
Theleftmostbitis1.Thenumberisnegative.
Leave10attherightaloneandcomplementthe
rest.Theresultis00001010.Thetwos
complementnumberis10.Sotheoriginal
numberwas10.
Note:
Twoscomplementcanbeachievedby
reversingallbitsexcepttherightmostbitsupto
thefirst1(inclusive).Ifyoutwoscomplement
apositivenumber,yougetthecorresponding
negativenumber.Ifyoutwoscomplementa
negativenumber,yougetthecorresponding
positivenumber.Ifyoutwoscomplementa
numbertwice,yougettheoriginalnumber.
Unsigned
-----------0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sign-andMagnitude
Ones
Complement
Twos
Complement
3.5
EXCESS
SYSTEM
Example 15
Represent25inExcess_127usingan8bit
allocation.
Solution
Firstadd127toget102.Thisnumberin
binaryis1100110.Addonebittomakeit8
bitsinlength.Therepresentationis
01100110.
Example 16
Interpret11111110iftherepresentationis
Excess_127.
Solution
Firstchangethenumbertodecimal.It
is254.Thensubtract127fromthe
number.Theresultisdecimal127.
3.5
FLOATINGPOINT
REPRESENTATION
Original
OriginalNumber
Number
Move
Normalized
--------------------------------------------6
+1010001.1101
x
2
-111.000011
x
6
+0.00000111001
x
3
-001110011
Figure 3-8
Example 19
Showtherepresentationofthenormalized
number+26x1.01000111001
Solution
Thesignispositive.TheExcess_127representationof
theexponentis133.Youaddextra0sontherightto
makeit23bits.Thenumberinmemoryisstoredas:
01000010101000111001000000000000
Number
-----------2
-2 x 1.11000011
+2-6 x 1.11001
-2-3 x 1.110011
Sign Exponent
---- ----------1
10000001
0
01111001
1
01111100
Mantissa
------------------------------11000011000000000000000
11001000000000000000000
11001100000000000000000
Example 20
Interpretthefollowing32bitfloatingpoint
number
10111110011001100000000000000000
Solution
Thesignisnegative.Theexponentis3(124
127).Thenumberafternormalizationis
23x1.110011
3.6
HEXADECIMAL
NOTATION