Beruflich Dokumente
Kultur Dokumente
CHAPTER
NUMBER SYSTEMS
OBJECTIVES
At the end of this chapter, students should be able to :
explore the relationship between decimal number system and number systems of
other bases (binary, octal, hexadecimal)
2.0
INTRODUCTION
This chapter emphasizes on the number systems in decimal (base 10), binary (base 2), octal
(base 8) and hexadecimal (base 16).
One of the important characters in numbering systems is the positional notation in every digit
within a number and the base being used. Every position of a digit contains a permanent
value. Comparisons of every digit among different bases are shown in the following table:
BASE
5th place
PLACE
1st
Single
place
unit
101
100
10
1
decimal
105
100,000
4th
place
104
10,000
3rd
place
103
1,000
2nd
place
102
100
24
16
23
8
22
4
21
2
20
1
binary
25
32
85
32,768
84
4,096
83
512
82
64
81
8
80
1
octal
hexadecimal
16
1,048,576
16
65,536
16
4,096
16
256
16
16
16
1
1st
place
10-1
0.1
1/10
2-1
0.5
1/2
8-1
0.125
1/8
16-1
0.0625
1/16
1.1
2nd place
3rd place
10-2
0.01
1/100
2-2
0.25
1/4
8-2
0.015625
10-3
0.001
1/1000
2-3
0.125
1/8
8-3
1.953125
X 103
1/512
16-3
2.4414062
X 104
1/4096
1/64
16-2
3.906 X
103
1/256
The following table shows the equivalent values for decimal numbers in binary, octal
and hexadecimal:
2.1.1
Decimal
Binary
Octal
Hexadecimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
1011 1100
+ 1100 1111
1 1000 1011
Example 2:
11
2.1.2
1001
11
0110
333
+ 476
1031
3 + 6 = 9 => 11
3 + 7 = 10 + 1 = 11 => 13
3 + 4 = 7 + 1 = 8 => 10
Example 4:
618
723
- 536
165
3 - 6 => 8 + 3 - 6 = 5
1 3 => 8 + 1 3 = 6
65=1
2.1.3
3 + 8 = 11 = B
2+2=4
A + C = 10 + 12 = 22 16 = 6 with carry 1
1+7+1=9
Example 6:
E 15 15
1F00A
B2
1EF58
A 2 = 10 2 = 8
0 B = 16 11 = 5
0 -> 16 1 = 15 = F
F1=E
1 -> 1
EXERCISE
1.
Perform the addition and subtraction for the following binary numbers:
a)
b)
c)
2.
d)
e)
f)
10001011 100111
11000 1111
1100110 111010
Perform the addition and subtraction for the following octal numbers:
a)
b)
c)
3.
10 + 111010
1000 + 1011
10011100 + 10111
677 + 2356
45 + 47
4007 + 112377
d)
e)
f)
673 - 25
6006 - 7
4510 - 571
Perform the addition and subtraction for the following hexadecimal numbers:
a)
b)
c)
B677 + CE79
21BA + ADD
9A3B + FACE
d)
e)
f)
A5 - 17
7AC - 3B1
FA51 - A76
2.2
=
=
=
=
=
=
18
9
4
2
1
0
balance
balance
balance
balance
balance
balance
1
0
1
0
0
1
(LSB)
(MSB)
Steps:
1.
2.
Therefore,
37.687510 = 100101.10112
2.2.2
1001102 = 3810
Example 10:
Convert 100110.11012 to decimal.
0.10112
= (1 X 2-1) + (1 X 2-2) + (0 X 2-3) + (1 X 2-4)
= 1/2 + 1/4 + 0 + 1/16
= (13/16)10 or 0.812510
From Example 9, 1001102 = 3810
Therefore, 100110.10112 = 38.812510
2.2.3
5638 = 37110
Example 12:
Convert 563.28 to decimal.
Steps:
563.28
= (5 X 82) + (6 X 81) + (3 X 80) + (2 X 8-1)
= 371 + (2 X 1/8)
= 371 + 1/4
= 371.2510
Therefore,
563.28 = 371.2510
2.2.4
=
=
1 balance 5
0 balance 1
(LSB)
(MSB)
10
5
2
1
0
balance
balance
balance
balance
balance
1
0
1
0
1
(LSB)
(MSB)
0.25
X 2
(MSB)
0.50
X 2
(LSB)
1.00
Therefore,
21.2510
= 10101 . 01002
= 15.416
Refer to conversion of
binary to hexadecimal
2.2.5
2.2.6
E5.A816 = 229.6562510
1111
00012
Example 18:
Convert 95AD16 to binary.
95AD16 =
1001
0101
1010
11012
2.2.7
2.2.8
2.2.9
011
100
111
010
1112
78
Binary
0001
1001
1001
0101
Octal
.
.
1010
1011
Example 22:
Convert 101111111000011.1101111001102 to hexadecimal and octal.
Hex
Binary
Octal
0101
1111
1100
0011
.
.
.
1101
1110
0110
Example 23:
The following shows the number representations for 2003 in binary, octal and
hexadecimal.
10
Decimal
200310
= (2 X 103) + (0 X 102) + (0 X 101) + (3 X 100)
= 2000 + 0 + 0 + 3
= 200310
Binary
Octal
Hexadecimal
7D316
= (7 X 162) + (13 X 161) + (3 X 160)
= 1792 + 208 + 3 = 200310
EXERCISE
1.
2.
3.
4.
5.
Decimal
1234
Binary
Octal
Hexadecimal
10110111
73
6FDA
11
6.
a)
b)
7.
43.62510
13.58
31.068
e)
f)
1A.3B16
e)
f)
CA.F116
BC.0116
a)
b)
2.3
c)
d)
13.43510
1101.1012
1001.011012
c)
d)
73.128
41.038
6E.A316
Binary
Hex
Character
Binary
Hex
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
100 0001
100 0010
100 0011
100 0100
100 0101
100 0110
100 0111
100 1000
100 1001
100 1010
100 1011
100 1100
100 1101
100 1110
100 1111
101 0000
101 0001
101 0010
101 0011
101 0100
101 0101
101 0110
101 0111
101 1000
101 1001
101 1010
41
42
43
44
45
46
47
48
49
4A
4B
4C
4D
4E
4F
50
51
52
53
54
55
56
57
58
59
5A
0
1
2
3
4
5
6
7
8
9
011 0000
011 0001
011 0010
011 0011
011 0100
011 0101
011 0110
011 0111
011 1000
011 1001
30
31
32
33
34
35
36
37
38
39
Space
Full stop
(
+
$
*
)
/
Comma
=
010 0000
010 1110
010 1000
010 1011
010 0100
010 1010
010 1101
010 1111
010 1100
010 1100
011 1101
20
2E
28
2B
24
2A
29
2D
2F
2C
3D
12
13
2.4
2.5
BCD
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
UNSIGNED NUMBERS
Unsigned numbers are numbers without signs. In other words, they are
numbers with only positive values. An 8-bit storage location can store any
unsigned integer of value between 0 and 255, a 16-bit storage location 0-65535.
The numbers that have been discussed before are all unsigned numbers.
2.6
2.6.1
Sign-And-Magnitude Representation
In daily usage, signed integers are represented by a plus or minus sign and
a value. This representation is known as sign-and-magnitude representation. A
sign cannot be used in the computer, but the uses of 0s and 1s take place. The
leftmost bit in a binary number is considered the sign bit. The remaining (n-1)
bits are used for the magnitude. A 0 sign bit represents a plus (positive) sign and
a 1 represents a minus (negative).
Example 24:
0100101
+
-
37
1100101
37
Example 25:
0000000000000001
(+1)
0111111111111111
(+32767)
1000000000000001
(-1)
1111111111111111
(-32767)
14
15
Example 26:
What is the decimal equivalent value of the sign-and-magnitude binary sequence
10111001?
The number is negative since its sign (the leftmost bit) is 1.
The magnitude of the number is given by the sequence of bits 0111001.
Now,
01110012 = (1 X 25) + (1 X 24) + (1 X 23) + (1 X 20)
= 32 + 16 + 8 + 1
= 57
Therefore , the decimal equivalent of the number 10111001 represented in
sign-and-magnitude is 57.
Addition of two numbers in sign-and-magnitude is carried out using the usual
conventions of binary arithmetic. However, if both numbers have the same sign,
the magnitude are added and the same sign is copied. If the signs are different,
the number that has the smaller magnitude is subtracted from the larger one.
If given n bits, in sign-and-magnitude representation, the range of numbers
that can be represented varies from 2n+1 + 2n-1 1. Therefore, if the result of an
arithmetic operation falls outside the range, the operation causes an overflow.
Example 27:
What is the decimal value of the sum of the binary numbers 10110011 and
00010110 if they are represented in sign-and-magnitude? Assume that the
basic unit is the byte.
Notice that the numbers have different signs: 10110011 is negative and
00010110 is positive.
To calculate their sum, it is necessary to find out which of these two numbers
has the larger magnitude.
Now,
Number :
Sign :
Magnitude :
Decimal
value
10110011
1 (negative)
0110011
= (1 X 25) + (1 X 24) +
(1 X 21) + (1 X 20)
= 32 + 16 + 2 + 1
= 51
-51
Number :
Sign :
Magnitude :
Decimal
value
00100110
0 (positive)
0100110
= (1 X 25) + (1 X 22)
+ (1 X 21)
= 32 + 4 + 2
= 38
+38
16
0000 0000
(0)
1111 1111
(-1)
1000 0000
(-128)
-(2n-1)
Step 3:
Example 28:
What is the 2s complement representation of 23?
Step 1:
Step 2:
Step 3:
17
Example 29:
What is the decimal positive value of the 2s complement number 11100011?
Follow steps 2 and 3 from the previous procedure since the number is negative:
Step 2:
Step 3:
13 + 31
13
31
44
ii)
0000 1101
0001 1111
0010 1100
21 5
510 = 0000 01012
1111 1010 (1s complement)
+
1
1111 1011 (2s complement)
21
0001 0101
-5
+
1111 1011
16
1 0001 0000
carry is discarded
iii)
EXERCISE
9 15
1510 = 0000 11112
1111 0000 (1s complement)
+
1
1111 0001 (2s complement)
9
0000 1001
-15 + 1111 0001
-6
1111 1010
18
1.
Convert the following binary numbers to decimal if they are represented in signand-magnitude:
a)
10001101
d)
11001010
b)
01100101
e)
01011001
c)
00011011
f)
103
2.
3.
Convert the following numbers to binary if they are represented in sign-andmagnitude, 1s complement and 2s complement:
No.
Decimal
Sign-and-Magnitude
1s
2s
complement
Complement
(a)
-12
(b)
-37
(c)
-59
(d)
-112
4.
What is the decimal value of the sum of the binary numbers 11101101 and
01001010 if they are represented in sign-and-magnitude? Assume that the
basic unit is the byte.
5.
By using the 2s complement method, perform the subtraction operation for the
followings:
a)
53
d)
57 63
b)
47
e)
61 27
c)
35 46
f)
13 104
19
2.9
Total number
of bits:
23
Sign
Biased Exponent
Mantissa (fraction)
Total number
of bits:
11
52
Sign
Biased Exponent
Mantissa (fraction)
Example 31:
Convert 12.5010 to the IEEE single precision floating point representation.
20
Steps:
The number is first converted into the format:
2n X 0.xxxxxx
where,
n : exponent
0.xxxxxx : mantissa
Now, the IEEE single precision format looks like,
Total number
of bits:
23
Sign
Biased Exponent
Mantissa (fraction)
To find the exponent and the mantissa, keep dividing the number by 2 till a fraction
between 0 and 1 results. The fraction is the mantissa value, the number of
divisions is the exponent value.
12.5 / 2 = 6.25
6.25 / 2 = 3.125
3.125 / 2 = 1.5625
1.5625 / 2 = 0.78125
Thus the values now are,
0.78125 X 24
The exponent bit pattern is stored using an excess of 127. This means that this
value is added to the exponent when storing (and subtracted when removing).
The exponent bit pattern to store is,
4 + 127 = 131 = 100000112
As the mantissa is a positive value, the sign bit is 0.
To work out the mantissa, each bit represents 2 to the power of a negative
number. It looks like,
1st bit of mantissa
2nd bit of mantissa
3rd bit of mantissa
4th bit of mantissa
5th bit of mantissa
etc
=
=
=
=
=
0.5
0.25
0.125
0.0625
0.03125
21
1 bits
8 bits
23 bits
10000010
Sign:(+ve)
Biased
Mantissa (fraction)
Exponent
Convert the number into hexadecimal,
0100 0001 0100 1000 0000 0000 0000 00002
= 4 1 4 8 0 0 0 016
Other ways of computing the floating point numbers representation are shown in
Examples 32 to 34.
Example 32:
Convert 0.510 to the IEEE single precision floating point format.
Steps:
1.
2.
3.
4.
1 bits
8 bits
23 bits
01111110
Sign:(+ve)
Biased Exponent
Mantissa (fraction)
22
Example 33:
Convert -1.510 to the IEEE single precision floating point format.
Firstly, convert 1.510 to binary:
0.5
1.510 = 1.12
X 2
1.0
= 1.1 X 20
=0
= 127 + 0 = 12710 = 0111 11112
=1
= 100 0000 0000 0000 0000 0000
(represented in 23 bits)
Therefore, the assembled format:
Significand
Exponent
Biased exponent
Mantissa
1 bits
8 bits
23 bits
01111111
Sign:(+ve)
Biased Exponent
Mantissa (fraction)
Example 34:
Convert 15/51210 to the IEEE single precision floating point format.
-15/512 = -15/29
= -15 X 2-9
= (-) 11112 X 2-9
=(-)1.1112 X 2-6
Sign-bit
Exponent
Biased exponent
Significand
Mantissa
= 1 (-ve)
= -6
= -6 + 127 = 12110 = 0111 10012
= 1.111
= 111 0000 0000 0000 0000 0000
(represented in 23 bits)
Therefore, the IEEE single precision floating point format:
1 bits
8 bits
23 bits
01111001
Sign:1
(-ve)
Biased Exponent
Mantissa (fraction)
23
Biased Exponent
Mantissa
= 0 (+ve)
= 1000 01012 = 13310
= 133 - 127 = 610
= 1100 10012
= 1.110010012 X 26
= 1 + (1 X 2-1) + (1 X 2-2) + (1 X 2-5) + (1 X 2-8) X 64
= 1 + 1/2+ 1/4+ 1/32 + 1/256 X 64
= 114.25
OR 1.11001001 x 26 = 1110010.01
= 64 + 32 + 16 + 2 +1/4
= 114.25
EXERCISE:
1.
Convert the following decimal numbers into the IEEE single precision floating point
representation:
a)
b)
c)
2.
15.5
171.625
7/64
d)
e)
f)
-12.625
-100.5
-21/128
BC800000
C2F00000
c)
d)
3C540000
6AF30000