Chapt 3 Number Representation
Chapt 3 Number Representation
Chapt 3 Number Representation
Number
Representation
OBJECTIVES
After learning this chapter, the reader should be able
to :Convert a number from decimal 、 hexadecimal,octal to
binary notation and vice versa.
Understand the different representations of an integer inside
a computer: unsigned, sign-and-magnitude, one’s complement,
and two’s complement.
position value:weight
Figure 3-2
Binary system
CONVERSION
Figure 3-3
Binary to decimal conversion
Example 1
Convert the binary number 10011 to decimal.
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 1 0 0 1 1
Weights 16 8 4 2 1
-------------------------------------
16 + 0 + 0 + 2 + 1
Decimal 19
Convert the binary number 1001.101 to decimal.
Solution
(1001.101)2
=1×23+0×22+0×21+1×20+1×2-1
+0×2-2+1×2-3
=8+1+0.5+0.125
=(9.625)10
Example 2
Convert the decimal number 35 to binary.
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 1 0 0 0 1 1
Figure 3-4
Decimal to binary conversion
3.3
HEXADECIMAL
NOTATION
Note:
Solution
Solution
Solution
Solution
8 B. C 4
1000 1011. 1100 0100
(8B.C4)16 = (10001011.110001)2
3.4
OCTAL
NOTATION
Note:
Solution
Solution
Solution
Solution
3 5 1. 6 5
011 101 001. 110 101
(351.65)8 = (11101001.110101)2
3.5
INTEGER
REPRESENTATION
Figure 3-5
Range of integers
Ranger: 0~ (2N-1)
Representation:
1.The number is changed to binary;
2.if the number of bits is less than N, 0s are
added to the left of the binary number so
that there is a total of N bits.
Example 3
Solution
Solution
Solution
Application:
1.Counting;
2.Addressing.
Sign-and-magnitude Format
In an 8-bit allocation:
+0 00000000
-0 10000000
Table 3.3 Range of sign-and-magnitude integers
# of Bits Range
---------- -------------------------------------------------------
8 127 0 +0 +127
16 32767 0 +0 +32767
32 0 +0 +2,147,483,647
Sign-and-magnitude Format
Representation:
1.The number is changed to binary;the sign is
ignored
2.if the number of bits is less than N-1, 0s are
added to the left of the binary number so that
there is a total of N-1 bits.
3.If the number is positive, o is added to the
left. If the number is negative, 1 is added to
the left.
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.
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
Interpretation:
1.Ignore the first bit.
2.Change the N-1 bits form binary to decimal
as shown at the beginning of the chapter..
3.Attach a + or a – sign to the number based
on the leftmost bit..
Example 8
Solution
# of Bits Range
--------- -------------------------------------------------------
8 127 0 +0 +127
16 32767 0 +0 +32767
32 0 +0 +2,147,483,647
One’s Complement Format
Representation:
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, every bit is
complemented(changed form 0 to 1 and 1 to
0).
Note:
Interpretation
1.If the leftmost bit is 0
a.Change the entire number from binary to
decimal.
b.Put a + in front of the number.
2. If the leftmost bit is 1
a.Complement the entire number .
b.Change the entire number from binary to
decimal.
c.Put a - in front of the number.
Example 11
Note:
# of Bits Range
--------- -------------------------------------------------------
8 128 0 +127
16 32,768 0 +32,767
32 0 +2,147,483,647
Two’s Complement Format
Representation:
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 0s and the first 1 unchanged.
Complement the rest of the bits.
Note:
Representation
1.Add the magic number to the integer.
Solution
To represent a floating-point
number(a number containing an integer
and a fraction),the number is divided
into two parts:the integer and the
fraction.
For example:
A Floating-point number 14.234
Integer:14
Fraction:0.234
Floating-Point representation
E
N ()2 S
Sign,Exponent and Mantissa
For example:
A number +1000111.0101 is Normalized, it
becomes,
+ 2 6
× 1.0001110101
sign + exponent 6 mantissa 0001110101
Sign,Exponent and Mantissa
0 10000101 01000111001000000000000
sign exponent mantissa
Table 3.11 Example of floating-point representation