UNIT- 1
NUMBER SYSTEMS
& CODES
Topic 1.2
Arithmetic in
Number System
1
BINARY ARITHMETIC
• BINARYADDITION
1
• BINARY SUBTRACTION
2
• BINARY MULTIPLICATION
3
• BINARY DIVISION
4
2
BINARY ADDITION
0 + 0 =0
1 + 0 =1
0 + 1 =1
1 + 1 = 0 1 (Carry bit)
1 1 0 1 (13 decimal)
+0 0 0 1 (+1 decimal)
1 1 1 0 (14 decimal)
3
BINARY ADDITION
- - - - (10 decimal)
10 +7 convert into
+ - - - (+7 decimal)
binary n then add
- - - - (-- decimal)
21 +30 convert into - - - - (21 decimal)
binary n then add + - - - (+30 decimal)
- - - - (-- decimal)
4
BINARY SUBTRACTION
0 ‐ 0 =0
1 ‐ 0 =1
0 ‐ 1 = 1 1 (Carry bit)
1 ‐ 1 =0 Borrow
1 1 0 1 (13 decimal)
- 0 0 1 1 (-3 decimal)
1 0 1 0 (10 decimal)
5
BINARY SUBTRACTION
10 – 4 convert into - - - - (10 decimal)
binary and then - - - - (- 4 decimal)
subtract - - - - (-- decimal)
14 – 6 convert into - - - - (14 decimal)
binary and then - - - - (- 6 decimal)
subtract - - - - (-- decimal)
6
BINARY MULTIPLICATION
1000 =810
X 0110
0000 =610
+1000
+1000
+0000
0110000 = 4810
7
BINARY MULTIPLICATION
---- =210
X ---- =710
- -- - - - - - - -
=??? 10
---- =610
X ---- =510
- -- - - - - - - -
8
=??? 10
BINARY DIVISION
011 ) 0 1 1 0 0 1 0 (1
011
000 (0
000
000 (0
000
001 (0
000
010 (0
Q=10000=1610
R=10= 210
31
BINARY DIVISION
Solution is
010)110110
Q=----2=---10
Q=----2=---10 R=---2= ---10
R=---2= ---10 31
BINARY DIVISION
31
BINARY DIVISION
31
Sign-Magnitude representation-
1. “ + ” sign before a number indicates it as a
positive number
2. “-” sign before a number indicates it as a negative
number
• Not very convenient on computers
• Replace “ + ”sign by “ 0 ”and “ - ”sign by “ 1 ”
(+1100101)2 = (01100101)2
(+101.001)2 = (0101.001)2
(-10010)2 = (110010)2
(-110.101)2 = (1110.101)2
Representing signed numbers
• 1's complement binary numbers are very
useful in Signed number representation.
Positive numbers are simply represented as
Binary number... But in case of negative
binary number representation, we represent
in 1's complement.
• If the number is negative then it is represented
using 1's complement.
Range of n-bit numbers
One's complement numbers:
0111111 --> + 63
0000110 --> + 6
0000000 --> + 0
1111001 --> - 6
1000000 --> - 63
December 2006 N.J. Rao M1L1 21
• 0 is represented by 000.....0
• 7- bit number covers the range from +63 to -63.
• n-bit number has a range from +(2n-1 - 1) to -(2n-1 - 1)
Example: One's complement
1111001= (1)(111001)
▪ First (sign) bit is 1: The number is
negative
▪ One’s Complement of
▪ 111001 is = 000110
=(6)10
December 2006 N.J. Rao M1L1 20
One's complement of a number
Complement all the digits-
• If A is an integer in one's complement form, then
one's complement of A = -A
This applies to fractions as well.
A = 0.101 , (+0.625)10
• One's complement of A = 1.010, (-0.625)10
December 2006 N.J. Rao M1L1 22
Mixed number
B = 010011.0101 , (+19.3125)10
One's complement of B = 101100.1010 , (- 19.3125)10
Two's Complement Representation
If MSD is a 0 -The number is positive
▪ Remaining (n-1) bits directly indicate the
magnitude If the MSD is 1-The number is negative
▪ Magnitude is obtained by complementing
all the remaining (n-1) bits and adding a 1
Two's complement allows negative and positive
numbers to be added together without any special
logic. ... This means that subtraction and addition
of both positive and negative numbers can all be
December 2006 N.J. Rao M1L1 23
done by the same circuit in the CPU.
Range of n-bit numbers
Two's complement numbers:
0111111 + 63
0000110 + 6
0000000 + 0
1111010 - 6
1000001 - 63
1000000 - 64
• 0 is represented by 000.....0
December 2006 N.J. Rao M1L1 25
• 7- bit number covers the range from +63 to -64.
• n-bit number has a range from +(2n-1 - 1) to -(2n-1)
Example: Two's complement
1111010 = (1)(111010)
First (sign) bit is 1:The number is negative
Complement 111010 and add 1= 000101 + 1
= 000110 = (6)10
December 2006 N.J. Rao M1L1 24
Two's complement of a number
Complement all the digits
If A is an integer in one's complement form, then
▪ Two's complement of A= -A
▪ This applies to fractions as well
▪ A = 0.101 , (+0.625)10
▪ Two's complement of A = 1.011(-0.625)10 Mixed
number
▪ B = 010011.0101, (+19.3125)10
December 2006 N.J. Rao M1L1 26
▪ Two's complement of B = 101100.1011, (- 19.3125)10
The brackets around the msb (the sign bit) are included here for
clarity but brackets are not normally used. Because only 7 bits
are used for the actual number, the range of values the system
can represent is from (−127)10 or (11111111)2, to (+127)10.
A comparison between signed binary, pure binary and decimal
numbers is shown in Table in next ppt. Notice that in the signed
binary representation of positive numbers between +010 and
+12710, all the positive values are just the same as in pure
binary.
Convert decimal number into 2’s complement
form,assuming an 8 bit binary representation for all
1) 1
2) 72
3) -127
Convert 2’s complement form into decimal
1) 1111
2) 001101
BINARY SUBTRACTION using 1’S
COMPLIMENT
The steps to be followed in subtraction by 1’s
complement are:
Suppose (A-B)
i) To write down 1’s complement of the subtrahend(B).
ii) To add this with the minuend(A).
iii) If the result of addition has a carry over then it is dropped
and an 1 is added in the first bit.
iv) If there is no carry over, then 1’s complement of the result of
addition is obtained to get the final result and it is negative.
25
BINARY SUBTRACTION
1’S COMPLIMENT
Step1-
0 0 0 0 0 1 0 1 (+5 decimal) 1
1 0 0 0 0 0 1 0 (-2 decimal)
0 1 1 1 1 1 0 1 (1’comp of -2) 2
1 000 0010
+ 1
0 0 0 0 0 1 1 (+3 decimal)
32
BINARY SUBTRACTION using 1’S
COMPLIMENT
Evaluate: 110101 – 100101
Solution:
1’s complement of 100101 is 011010. Hence
Minued - 110101
1’s complement of subtrahend - 011010
Carry over - 1 001111
010000
27
BINARY SUBTRACTION using 1’S
COMPLIMENT
Evaluate: 1011001 – 1101010
Solution:
1’s complement of 1101010 is 0010101. Hence
Minued - 1011001
1’s complement of subtrahend - 0010101
no Carry(ans) - 1101110
Convert ans. into 1’s complement again 00100 01
1011001 – 1101010= 0010001
28
BINARY SUBTRACTION using 1’S
COMPLIMENT
1011.001 – 110.10
Solution:
1’s complement of 0110.100 is 1001.011 Hence
Minued - 1011.001
1’s complement of subtrahend - 1001.011
Carry over - 1 0100.100
0100.101
Hence the required difference is 100.101 29
BINARY SUBTRACTION using 1’S
COMPLIMENT
1) Evaluate: 1111 – 0110 3) 10110.01 – 11010.10
1s complement of (B)=00101.01
Solution: ??
Add(A+B) 1 0 1 1 0 .0 1
0 0 1 0 1 .0 1
2) 101011 – 111001
1 1 0 1 1 .1 0
Solution: ??
No carry ,convert ans. into 1’s
complement=(00100.01)
30
BINARY SUBTRACTION using 2’S
COMPLIMENT
The operation is carried out by means of the following
steps:
(A-B)
(i) At first, 2’s complement of the subtrahend(B) is found.
(ii) Then it is added to the minuend(A).
(iii) If the final carry over of the sum is 1, it is dropped and the
result is positive.
(iv) If there is no carry over, the two’s complement of the sum
will be the result and it is negative.
31
BINARY SUBTRACTION using 2’S
COMPLIMENT
(i) 110110 - 10110
Solution:
The numbers of bits in the subtrahend is 5 while that of minuend is
6. We make the number of bits in the subtrahend equal to that of
minuend by taking a `0’ in the sixth place of the subtrahend.
Now, 2’s complement of 010110 is (101101 + 1) i.e.101010. Adding
this with the minuend.
1 10110 Minuend
1 01010 2’s complement of subtrahend
Carry over 1 100000 Result of addition
After dropping the carry over we get the result of subtraction to be 100000.
32
BINARY SUBTRACTION using 2’S
COMPLIMENT
(ii) 10110 – 11010
Solution:
2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence
Minued - 10110
2’s complement of subtrahend - 00110
Result of addition - 11100
As there is no carry over, the result of subtraction is negative and
is obtained by writing the 2’s complement of 11100 i.e.(00011 +
1) or 00100.
Hence the difference is – 100.
33
BINARY SUBTRACTION using 2’S
COMPLIMENT
(ii) 10110 – 11010
Solution:
2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence
Minued - 10110
2’s complement of subtrahend - 00110
Result of addition - 11100
As there is no carry over, the result of subtraction is negative and
is obtained by writing the 2’s complement of 11100 i.e.(00011 +
1) or 00100.
Hence the difference is – 100.
34
BINARY SUBTRACTION using 2’S
COMPLIMENT
.
(iii)1010.11 – 1001.01
Solution:
2’s complement of 1001.01 is 0110.11. Hence
Minued - 1010.11
2’s complement of subtrahend - 0110.11
Carry over 1 0001.10
After dropping the carry over we get the result of
subtraction as 1.10.
35
EXAMPLES
---- - - - - (+6 decimal) 1
---- - - - - (-4 decimal)
---- - - - - (1’comp of -4)
---- - - - - (2’s comp of -4) 2
- ---- - - - - (-- decimal)
EXAMPLES
---- - - - - (+7 decimal) 1
---- - - - - (-3 decimal)
---- - - - - (1’comp of -3)
---- - - - - (2’s comp of -3) 2
1 2 - ---- - - - - (-- decimal)
OCTAL ARITHMETIC
• OCTAL ADDITION
1
• OCTAL SUBTRACTION
2
• OCTAL MULTIPLICATION
3
• OCTAL DIVISION
4
38
OCTAL ARITHMETIC
• OCTAL ADDITION
1
Note-Perform addition but if addition is grater
than or equal to 8 then subtract from 8 and
also generate carry bit.
39
1. OCTAL ADDITION
(i) (162)8 + (537) 8
Solution:
1 1 -------- Carry bit
1 6 2
5 3 7
7 10 9
- 8 8
7 2 1
Therefore, sum = 7218
OCTAL ADDITION
(136) 8 + (636) 8
Solution:
1 <---- carry
136
+
636
774
Therefore, sum = 7748
OCTAL ADDITION
(25.27) 8 + (13.2) 8
Solution:
1 <---- carry
25.27
13.2
40.47
Therefore, sum = (40.47) 8
OCTAL ADDITION
(167) 8 + (425) 8
Solution: ??
OCTAL ARITHMETIC
• OCTAL SUBTRACTION
2
44
OCTAL SUBTRACTION
The Following methods can be used for octal
subtraction:-
1) Direct Subtraction.
2) Convert the no. to binary, perform the
subtraction and convert the result back to
Octal.
3) Use the 7’s complement method.
4) Use the 8’s complement method.
45
OCTAL SUBTRACTION
1)Direct Subtraction-
i)456-173=
ii)653-177= ??
46
OCTAL SUBTRACTION using 7’s complement
3)Use 7’s complement method-
i) Find 7’s complement of (512)
777
- 512
265
Hence 7’s Complement of(512) is (265)
47
OCTAL SUBTRACTION using 7’s complement
3)Use 7’s complement method-
Procedure of subtraction using 7’s
complement ,Eg.(A-B)
1.At first, find 7's complement of the B
(subtrahend).
2. Then add it to the A (minuend).
3. If the final carry over of the sum is 1, then it
is dropped and 1 is added into the result.
4. If there is no carry over, then 7's complement
of the sum is the final result and it is negative.
48
Find Subtraction of 342 and 614 using 7's complement method
Solution:
Here A = 342, B = 614.
Find A - B = ? using 7's complement
7's complement of a number is obtained by subtracting all bits from 777.
7's complement of 614 is
7 7 7
- 6 1 4
1 6 3
Now Add this 7's complement of B to A
1
3 4 2
+ 1 6 3
5 2 5
Here there is no carry, answer is - (7's complement of the sum obtained)
7's complement of a number is obtained by subtracting all bits from 777.
7's complement of 525 is
7 7 7
- 5 2 5
2 5 2
So answer is -252
49
OCTAL SUBTRACTION using 7’s complement
Use 7’s complement method-
find (161)8 – (243)8
Sloution =??
OCTAL SUBTRACTION using 8’s complement
4)Use 8’s complement method-
i)Find 8’s complement of (512)
777
- 512
265
1 (Add 1 to 7’s complement)
2 6 6
Hence 8’s Complement of(512) is (266)
51
OCTAL SUBTRACTION using 8’s
complement
4)Use 8’s complement method-
1. At first, find 8's complement of the
B(subtrahend).
2. Then add it to the A(minuend).
3. If the final carry over of the sum is 1, then it
is dropped and the result is positive.
4. If there is no carry over, then 8’s
complement of the sum is the final result
and it is negative.
52
Here A = 342, B = 614.
Find A - B = ? using 8's complement
8's complement of a number is 1 added to it's 7's complement number.
7's complement of 614 is
7 7 7
- 6 1 4
1 6 3
Now add 1 : 163 + 1 = 164
Now Add this 8's complement of B to A
1
3 4 2
+ 1 6 4
5 2 6
Here there is no carry, answer is - (8's complement of the sum obtained)
8's complement of a number is 1 added to it's 7's complement number.
7's complement of 526 is
7 7 7
- 5 2 6
2 5 1
Now add 1 : 251 + 1 = 252
So answer is -252
OCTAL SUBTRACTION using 8’s complement
Use 8’s complement method-
find (536)8 – (345)8
Solution =??
OCTAL ARITHMETIC
• OCTAL MULTIPLICATION
3
55
OCTAL MULTIPLICATION
Step1 – Convert both octal no. to binary
Step 2 – perform simple binary multiplication
Step 3 - After performing multiplication,
whatever answer you get in binary ,convert it to
equivalent octal number.
Eg . (12)*(7)=
Step1-Convert into binary- (12)= 001010
(7) = 111
Step 2- 1010
* 111
1000110
Step 3 - 1 0 6 ans. is =(106)8 56
OCTAL ARITHMETIC
• OCTAL DIVISION
4
57
OCTAL DIVISION
Step1 – Convert both octal no. to binary
Step 2 – perform simple binary Division.
Step 3 - convert given binary quotient and
reminder to octal number.
Eg. (24)/(4)=
Step1-Convert into binary- (24)= 010100
(4) = 100
Step 2- 100)10100( 101 quotient
000 reminder
Step 3- Convert into octal (101)2 = (5)8
58
Octal Multiplication
Solve 14* 5= ??
Octal Division
Solve 5)30 = ??
HEXADECIMAL ARITHMETIC
• HEXA.ADDITION
1
• HEXA. SUBTRACTION
2
• HEXA. MULTIPLICATION
3
• HEXA. DIVISION
4
60
HEXADECIMAL ARITHMETIC
• HEXA.ADDITION
1
61
HEXADECIMAL ADDITION
Add 9 +8
1 Carry bit
9
+8
17
- 16
1
1 1
62
HEXADECIMAL ADDITION
63
HEXADECIMAL ADDITION
Add A1 +23 =
Solution = ??
64
HEXADECIMAL ARITHMETIC
• HEXA. SUBTRACTION
2
65
HEXADECIMAL SUBTRACTION
The Following methods can be used for octal
subtraction:-
1) Direct Subtraction.
2) Convert the no. to binary, perform the
subtraction and convert the result back to
Hexadecimal.
3) Use the 15’s complement method.
4) Use the 16’s complement method.
66
HEXADECIMAL SUBTRACTION
1)Direct Subtraction-
Eg.73 -1C=
6 16 (3 is less than 12 so we add 16)
7 3
- 1 12
5 7
67
HEXADECIMAL SUBTRACTION
1)Direct Subtraction-
68
REPRESENTATION OF NEGATIVE
NUMBER
15’S COMPLIMENT
1.At first, find 15's complement of the
B(subtrahend).
2. Then add it to the A(minuend).
3. If the final carry over of the sum is 1, then it is
dropped and 1 is added to the result.
4. If there is no carry over, then 15's complement of
the sum is the final result and it is negative.
69
Here A = B06, B = C7C.
Find A - B = ? using 15's complement
15's complement of a number is obtained by subtracting all bits from FFF.
15's complement of C7C is
F F F
- C 7 C
3 8 3
Now Add this 15's complement of B to A
B 0 6
+ 3 8 3
E 8 9
Here there is no carry, answer is - (15's complement of the sum obtained)
15's complement of a number is obtained by subtracting all bits from FFF.
15's complement of E89 is
F F F
- E 8 9
1 7 6
So answer is -176
REPRESENTATION OF NEGATIVE
NUMBER
16’S COMPLIMENT
1.At first, find 16's complement of the
B(subtrahend).
2. Then add it to the A(minuend).
3. If the final carry over of the sum is 1, then it is
dropped and the result is positive.
4. If there is no carry over, then 16's
complement of the sum is the final result and it
is negative.
71
Here A = B06, B = C7C.
Find A - B = ? using 16's complement
16's complement of a number is 1 added to it's 15's complement number.
15's complement of C7C is
F F F
- C 7 C
3 8 3
Now add 1 : 383 + 1 = 384
Now Add this 16's complement of B to A
B 0 6
+ 3 8 4
E 8 A
Here there is no carry, answer is - (16's complement of the sum obtained)
16's complement of a number is 1 added to it's 15's complement number.
15's complement of E8A is
F F F
- E 8 A
1 7 5
Now add 1 : 175 + 1 = 176
So answer is -176
HEXADECIMAL ARITHMETIC
• HEXA. MULTIPLICATION
3
73
HEXADECIMAL MULTIPLICATION
Step1 – Convert both hexadecimal number to binary
Step 2 – perform simple binary multiplication
Step 3 - After performing multiplication, whatever
answer you get in binary ,convert it to equivalent
hexadecimal number.
Eg . (12)*(7)=
Step1-Convert into binary- (8)= 1000
(7) = 0111
Step 2- 1 0 0 0
*0111
0111000
Step 3 - 3 8 ans. is =(38)16 74
HEXADECIMAL ARITHMETIC
• HEXA. DIVISION
4
75
HEXADECIMAL DIVISION
Step1 – Convert both hexadecimal number to binary
Step 2 – perform simple binary Division.
Step 3 - convert given binary quotient and reminder
to hexadecimal number.
Eg. (24)/(8)=
Step1-Convert into binary- (24)= 00100100
(8) = 1000
Step 2- 1000)100100( 100 quotient
100 reminder
Step 3- Convert into hexadecimal
Quotient (0100)2 = (4)16 , Reminder (0100)2 = (4)16
76