Chapter Four Number Systems and Codes
Chapter Four Number Systems and Codes
CHAPTER FOUR
Example 4.1
( 83 )10 = 8 * 101 + 3 * 100
= 8 * 10 + 3 * 1
= 80 +3
The digit 8 has a weight of 10 (101), and the digit 3 has a weight of 1 (100).
Example 4.2
(724)10 = 7 * 102 + 2 * 101 + 4 * 100
= 7 * 100 + 2 * 10 + 4 * 1
= 700 + 20 + 4
The digit 7 has a weight of 100 (102), the digit 2 has the weight of 10 (101),
and the digit 4 has the weight of 1 (100).
From the table 4.1 it is clear that to cont from (0)10 to (31)10 in binary
numbers system we need at least five bits. The following formula decides
how high we can count with n bits, beginning with zero:
Example 4.3
With two bits and using equation 4.1 we can count from (0)10 to (3)10
22 – 1 = 4 – 1 = 3
With six bits and using equation 4.1 we can count from (0)10 to (63)10
26 – 1 = 64 – 1 = 63
Example 4.4
(110)2 = 1 * 22 + 1 * 21 + 0 * 20
=1*4+1*2+0*1
=4+2+0
= (6)10
Starting from the left, bit 1 has a weight of 4 ( 22 ), bit 1 has the weight of
2 ( 21 ), and the bit 0 has the weight of 1 ( 20 ).
Example 4.5
( 10110.1 )2 = 1 * 24 + 0 * 23 + 1 * 22 + 1 * 21 + 0 * 20 + 1 * 2-1
= 1 * 16 + 0 * 8 + 1 * 4 + 1 * 2 + 0 * 1 + 1 * 1/2
= 16 + 0 + 4 + 2 + 0 + 0.5
= ( 22.5 )10
Starting from the left, bit 1 has a weight of 16 ( 24 ), bit 0 has a weight of
8 (23), bit 1 has a weight of 4 ( 22 ), bit 1 has a weight of 2 ( 21 ), bit 0 has
a weight of 1 ( 20 ). Then bit 1 after the binary point has a weight of 0.5
(2-1).
Example 4.6
(101.1011)2 = 1 * 22 + 0 * 21 + 1 * 20 + 1 * 2-1 + 0 * 2-2 + 1 * 2-3 + 1 * 2-4
= 1* 4 + 0*2 + 1 * 1 + 1 * 0. 5 + 0 * 0.25 + 1* 0.125 + 1* 0.0625
= 4 + 0 + 1 + 0.5 + 0 + 0.125 + 0.0625
= 5.6875
Homework
Convert the following binary numbers to decimal numbers.
a. (110110)2 b. (11010.101)2
Answer a. (54)10 b. (26.625)10
Example 4.7
( 7 )10 = 4 + 2 + 1 = 1 * 4 + 1 * 2 + 1 * 1 = 1 * 22 + 1 * 21 + 1 * 20
= ( 111 )2
(13)10 = 8 + 4 + 0 +1
= 1 * 8 + 1 * 4 + 0*2 + 1*1 = 1*23 + 1*22 + 0*21 + 1* 20
= (1101)2
Example 4.8
Convert the following decimal numbers to their equivalent binary
numbers:
(a). ( 11 )10 (b). ( 34 )10 (c). ( 45 )10
Solution
(a). 11/2 (b). 34/2 (c). 45/2
5/2 1 → LSB 17/2 0 → LSB 22/2 1 → LSB
2/2 1 8/2 1 11/2 0
1/2 0 4/2 0 5/2 1
0 1 → MSB 2/2 0 2/2 1
1/2 0 1/2 0
0 1 → MSB 0 1 → MSB
Example 4.9
( 0.625 )10 = 0.5 + 0 + 0.125 = 1 * 2-1 + 0 * 2-2 + 1 * 2-3 = (0.101)2
Example 4.10
Convert the following decimal fraction numbers to there equivalent
binary fraction numbers:
(a). ( 0.625 )10 (b). ( 0.3125 )10
Solution
Carry Carry
(a). 0.625 * 2 = 1.25 1 → MSB (b). 0.3125 * 2 = 0.625 0 → MSB
0.25 * 2 = 0.5 0 0.625 * 2 = 1.25 1
0.5 * 2 = 1.0 1 → LSB 0.25 * 2 = 0.5 0
0.5 * 2 = 1.0 1 → LSB
Homework
Convert the decimal number (37.375)10 to binary number using: -
1. Sum-of-weights method.
2. Repeated division-by-2 method.
Answer (100101.011)2
1. Binary addition
There are four basic rules for adding binary digits (bits):
0+0=0
0+1=1
1+0=1
1 + 1 = 0 with carry of 1
Note: For the last rule, the result of addition is a sum of (0) in a given
column and a carry of (1) over to the next higher column
Example 4.11
(a) 111→ carry 1→ carry
111 7
+11 +3
1010 10
2. Binary subtraction
There are four basic rules for subtracting binary digits (bits):
0-0=0
1-1=0
1-0=1
0 - 1 = 1 with a borrow of 1
Example 4.12
(a) 110 6 (b) 110 6 (c) 1010 10
-100 -4 - 011 -3 - 0101 -5
010 2 011 3 0101 5
Note: No borrow were needed in part (a), while borrows were needed in
(b) and (c).
3. Binary multiplication
There are four basic rules for multiplying binary digits (bits):
0*0=0
0*1=0
1*0=0
1*1=1
Example 4.13
(a) 11 3 (b) 111 7 (c) 1110 14
*11 *3 * 11 *3 *1001 * 9
11 9 111 21 1110 126
11 111 0000
1001 10101 0000
1110
1111110
4. Binary division
Binary division follows the same procedure as division in decimal
system.
Example 1.14
(a) 11 (b) 11
10 110 101 1111
10 101
010 0101
10 101
00 000
Homework
Perform the following arithmetic operations: -
a. 010111 + 001100 b. 1011 – 0110 c. 1010 * 1001 d. 1100 ÷ 0100
Answers a. 100011 b. 0101 c. 1011010 d. 0011
Example 4.15
Binary number 1’S Complement
1010 0101
11010 00101
110111 001000
1011011 0100100
Example 4.16
Subtract (1011)2 from (1110)2 using the 1’S Complement method.
Solution
a. Using Direct Method b. Using 1’S Complement Method
1110 1110
-1001 +0100 →1’S Complement
0101 10010
+1 → Carry
0011 → Result
Example 4.17
Subtract (1110)2 from (1011)2 using the 1’S Complement method.
Solution
a. Using Direct Method b. Using 1’S Complement Method
1011 1011
-1110 +0001 →1’S Complement of 1110
Final answer→ -0011 1100 →1’S Complement of the answer
with opposite sign
- 0011 → Final answer
Homework
Perform the following subtractions using the 1’S complement method.
a. 100 – 011 b. 1000 – 1101
Answer a. 001 b. - 0101
Example 4.18
Convert the following binary numbers to their 2’S Complements.
a. 101 b. 10011
Solution
a. 010 → 1’S Complement of the binary number 101
+1 → adding 1
011 → 2’S Complement of the number 101
10-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes
Example 4.20
Subtract (1110)2 from (1011)2 using the 2’S Complement method.
Solution
a. Using Direct Method b. Using 1’S Complement Method
1011 1011
-1110 +0010 →2’S Complement of 1110
Final answer → -0011 1101 →2’S Complement of the answer
with negative sign
-0011 → Final answer
Homework
Perform the following subtractions using the 2’S complement method.
a. 100 – 011 b. 1000 – 1101
Answer a. 001 b. – 0101
Example 4.21
Determine the decimal equivalent of the following signed binary
numbers:
a. (01011001)2 b. (10011100)2
12-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes
Solution
From the definition of signed binary numbers, it is clear that (01011001)2
is a positive number since the most significant bit is 0 and, the number
(10011100)2 is a negative number since the most significant bit is 1. The
solution will be as follows:-
b. (10011100)2 = - (0 * 26 + 0 * 25 + 1 * 24 + 1 * 23 + 1 * 22 + 0 * 21 + 0 * 20)
= - (0 + 0 + 16 + 8 + 4 + 0 + 0)
= (-28)10 Answer
Example 4.22
Determine the signed binary equivalent of the following decimal
numbers. Express the resultant signed binary number in eight bit (byte)
form:-
a. (+41)10 b. (- 47)10
Solution
Since the desired equivalent signed binary numbers have to be
expressed in eight bit form, therefore the first seven LSB’s will stands
for the magnitude and the remaining eighth bit (MSB ) stands for the
signed bit. The solution will be as follows:-
13-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes
Homework
1. Determine the decimal equivalent of the following signed numbers: -
a. (10010001)2 b. (00110111)2
Answer a. ( -17 )10 b. ( +55 )10
2. Express, the following signed decimal numbers in 1’s complement
form using byte representation: -
a. ( -22 )10 b. ( -11 )10
Answer a. (11101001)2 b. (11110100)2
3. Express, the signed numbers shown in question 2 above in 2’s
complement form.
Answer a. (11101010)2 b. (11110101)2
14-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes
Note. When the number of bits in the sum exceeds the number of bits
in each of the numbers added, overflow results.
Example 4.23
Add (+15)10 to (+55)10. Use eight bits (byte) to represent each signed
binary numbers.
Solution
Since both numbers are positive, therefore the sign bits are 0’s, and
there is no need to 2’S Complement.
(+15)10 → 00001111
+(+55)10 → +00110111
(+70)10 01000110 → Answer
(+) Sign ┘ └Magnitude (70)
b. Adding small negative number to a larger positive one
(1) Take the 2’S complement of the magnitude of the negative
number, and leave the sign bit as it is. The positive number
remains in true form.
(2) Add the two numbers, including the sign bits of both. The
final carry discarded.
(3) The sign bit of the sum will be a 0 ( + ), and the magnitude
will be in true form.
(4) In this case, no overflow is possible.
15-32 Yacoup k.
Hanna
Computer Architecture
Chapter Four Number Systems and Codes
Example 4.24
Add (-6)10 to (+15)10. Use eight bits (byte) to represent the signed
numbers.
Solution
(+15)10 → 00001111
+(-6)10 → +11111010 →2’s complement of -6
(+9)10 discard carry← 1 00001001 → Answer
(+) Sign ┘ └Magnitude (9)
Example 4.25
Add (-15)10 to (+6)10. Use eight bits (byte) to represent the signed numbers.
Solution
(+6) 10 → 00000110
+(-15) 10 → +11110001 → 2’s complement of (-15)
(-9) 10 11110111 → Answer
└ 2’s complement of ( - 9 )
16-32 Yacoup k.
Hanna