Chp2 Numberingsystem
Chp2 Numberingsystem
CHAPTER 2
NUMBER SYSTEMS
OBJECTIVES
At the end of this chapter, students should be able to :
understand how integers and fractional numbers are represented in binary
explore the relationship between decimal number system and number systems of
other bases (binary, octal, hexadecimal)
understand signed numbers and unsigned numbers
understand number representations in two’s complement
perform arithmetic operations in every base
understand the method of floating point number representation in IEEE format
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:
PLACE
BASE th
5 place 4th
3rd
2nd
1st
Single ● 1st 2nd place 3rd place
place place place place unit place
105 104 103 102 101 100 ● 10-1 10-2 10-3
decimal 100,000 10,000 1,000 100 10 1 0.1 0.01 0.001
1/10 1/100 1/1000
25 24 23 22 21 20 ● 2-1 2-2 2-3
binary 32 16 8 4 2 1 0.5 0.25 0.125
1/2 1/4 1/8
85 84 83 82 81 80 ● 8-1 8-2 8-3
32,768 4,096 512 64 8 1 0.125 0.015625 1.953125
octal
X 103
1/8 1/64 1/512
5 4 3 2 1 0
16 16 16 16 16 16 ● 16-1 16-2 16-3
1,048,576 65,536 4,096 256 16 1 0.0625 3.906 X 2.4414062
hexadecimal
103 X 104
1/16 1/256 1/4096
2
Example 1:
11111
1011 1100
+ 1100 1111
1 1000 1011
Example 2:
11
1001
+ 11
0110
Example 3:
1 1 1
333 3 + 6 = 9 => 11
+ 476
3
1031 3 + 7 = 10 + 1 = 11 => 13
3 + 4 = 7 + 1 = 8 => 10
Example 4:
618
723 3 - 6 => 8 + 3 - 6 = 5
- 536 1 – 3 => 8 + 1 – 3 = 6
165 6–5=1
Example 5:
1A23 3 + 8 = 11 = B
+ 7C28 2+2=4
964B A + C = 10 + 12 = 22 –16 = 6 with carry 1
1+7+1=9
Example 6:
E 15 15
1F00A A – 2 = 10 – 2 = 8
- B2 0 – B = 16 – 11 = 5
0 -> 16 – 1 = 15 = F
1EF58 F–1=E
1 -> 1
EXERCISE
1. Perform the addition and subtraction for the following binary numbers:
2. Perform the addition and subtraction for the following octal numbers:
3. Perform the addition and subtraction for the following hexadecimal numbers:
a) B677 + CE79 d) A5 - 17
b) 21BA + ADD e) 7AC - 3B1
c) 9A3B + FACE f) FA51 - A76
4
Example 7:
Convert 3710 to binary.
Steps:
37 ÷ 2 = 18 balance 1
18 ÷ 2 = 9 balance 0
9÷2 = 4 balance 1
4÷2 = 2 balance 0
2÷2 = 1 balance 0
1÷2 = 0 balance 1
Example 8:
What is the value of 37.687510 in binary?
Steps:
Example 9:
Convert 1001102 to decimal.
Steps:
1001102
= (1 X 25) + (0 X 24) +(0 X 23) +(1 X 22) + (1 X 21) + (0 X 20)
= 32 + 0 + 0 + 4 + 2 + 0
= 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
Example 11:
Convert 5638 to decimal.
Steps:
5638
= (5 X 82) + (6 X 81) + (3 X 80)
= 320 + 48 + 3
= 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
Example 13:
Convert 2110 to hexadecimal.
Steps:
21 ÷ 16 = 1 balance 5
1 ÷ 16 = 0 balance 1
Example 14:
Convert 21.2510 to hexadecimal.
Steps:
From Example 7,
21 ÷ 2 = 10 balance 1
10 ÷ 2 = 5 balance 0
5÷2 = 2 balance 1
2÷2 = 1 balance 0
1÷2 = 0 balance 1
Now, 0.25
0.25
X 2
0 0.50
X 2
1 1.00
** convert 10 → 2 → 16
So, (0.25)10 = (0.01)2
- Refer to conversion of
binary to hexadecimal
7
8
9
Example 15:
Convert E516 to decimal.
Steps:
E516
= (E X 161) + (5 X 160)
= (14 X 16) + (5 X 1)
= 224 + 5
= 22910
Example 16:
Convert E5.A816 to decimal.
Steps:
Hex E 5 . A 816
Binary 1110 0101 . 1010 10002
From Example 15, E516 = 22910
Now,
(0.1010 1000)2
= (1 X 2-1) + (0 X 2-2) + (1 X 2-3) + (0 X 2-4) + (1 X 2-5) +
(0 X 2-6) + (0 X 2-7) + (0 X 2-8)
= 1/2 + 1/23 + 1/25
= 1/2 + 1/8 + 1/32
= 0.5 + 0.125 + 0.03125
= (0.65625)10
Method:
Get the binary representation for every digit in the hexadecimal number.
Example 17:
Convert F116 to binary.
F 1
11
Example 18:
Convert 95AD16 to binary.
9 5 A 1
Example 19:
Convert 111001110101112 to hexadecimal.
Example 20:
Convert the binary number in Example 13 to octal.
3 4 7 2 78
Example 21:
Convert 1995.AB16 to binary and octal.
Hex 1 9 9 5 . A B
.
Binary 0001 1001 1001 0101 1010 1011
.
Octal 0 1 4 6 2 5 5 2 6
12
Example 22:
Convert 101111111000011.110111100110 2 to hexadecimal and octal.
Hex 5 F C 3 . D E 6
.
Binary 0101 1111 1100 0011 1101 1110 0110
.
Octal 0 5 7 7 0 3 6 7 4 6
13
14
EXERCISE
Example 24:
Example 25:
What is the sign-and-magnitude representation of the decimal numbers –31 and
+31 if the basic unit is a byte?
Since the number +31 is positive, the sign bit is set to 0. The remaining 7 bits
will be used to represent the magnitude.
The binary representation of decimal 31 is given by the following sequence
0011111. That is, 3110 = 00111112.
The sign-and-magnitude representation of the number is 00011111 2.
To represent the sign-and-magnitude of –31, the sign bit is changed from 0 to 1.
Since the binary representation in its magnitude is the same, therefore, the sign-
and-magnitude of –31 is 100111112
Example 26:
What is the decimal equivalent value of the sign-and-magnitude binary sequence
10111001?
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,
Example 28:
What is the 2’s complement representation of –23?
Example 29:
What is the decimal positive value of the 2’s complement number 11100011?
Follow steps 2 and 3 from the previous procedure since the number is negative:
Example 30:
Perform the following operation in 8-bit 2’s complement.
i) 13 + 31
13 0000 1101
31 + 0001 1111
44 0010 1100
ii) 21 – 5
510 = 0000 01012
1111 1010 (1’s complement)
+ 1
1111 1011 (2’s complement)
21 0001 0101
-5 + 1111 1011
16 1 0001 0000
carry is discarded
iii) 9 + (– 15)
1510 = 0000 11112
1111 0000 (1’s complement)
+ 1
1111 0001 (2’s complement)
9 0000 1001
-15 + 1111 0001
-6 1111 1010
21
EXERCISE
1. Convert the following binary numbers to decimal if they are represented in sign-
and-magnitude:
a) 10001101 d) 11001010
b) 01100101 e) 01011001
c) 00011011 f) 103
22
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 2’s complement method, perform the subtraction operation for the
followings:
a) 5–3 d) 57 – 63
b) 4–7 e) 61 – 27
c) 35 – 46 f) 13 – 104
23
i) IEEE Short Real: 32 bits 1 bit for the sign, 8 bits for the exponent, and
23 bits for the mantissa. Also called single
precision.
Total number
of bits: 1 8 23
ii) IEEE Long Real: 64 bits 1 bit for the sign, 11 bits for the exponent,
and 52 bits for the mantissa. Also called
double precision.
Total number
of bits: 1 11 52
Example 31:
24
Steps:
2n X 0.xxxxxx
where,
n : exponent
0.xxxxxx : mantissa
Total number
of bits: 1 8 23
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
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).
However, the mantissa is normalized, by moving the bit patterns to the left (each
25
shift subtracts one from the exponent value) till the first 1 drops off.
10010000000000000000000
Other ways of computing the floating point numbers representation are shown in
Examples 32 to 34.
26
Example 32:
Convert 0.510 to the IEEE single precision floating point format.
Steps:
mantissa
0.510 = 0.12 X 20
= 1.0 X 2-1
Mantissa = 0
= 000 0000 0000 0000 0000 0000 (represented in 23 bits)
Example 33:
Convert -10.510 to the IEEE single precision floating point format.
Significand = 1.1 X 20
Exponent = 0
Biased exponent = 127 + 0 = 12710 = 0111 11112
Mantissa = 1
= 100 0000 0000 0000 0000 0000
(represented in 23 bits)
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 = 1 (-ve)
Exponent = -6
Biased exponent = -6 + 127 = 12110 = 0111 10012
Significand = 1.111
Mantissa = 111 0000 0000 0000 0000 0000
(represented in 23 bits)
Example 35:
Convert the IEEE single precision floating point format 42E48000h to decimal.
Sign-bit = 0 (+ve)
Biased Exponent = 1000 01012 = 13310
Actual Exponent = 133 - 127 = 610
Mantissa = 1100 10012
Significand = 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) 15.5 d) -12.625
b) 171.625 e) -100.5
c) 7/64 f) -21/128
a) BC800000 c) 3C540000
b) C2F00000 d) 6AF30000