Arithmetic Operations
Arithmetic operations in a computer are done using binary numbers and not decimal numbers and these take place in its arithmetic unit. The electronic circuit of a binary adder with suitable shift register can perform all arithmetic operations.
Binary Arithmetic
The arithmetic rules for Addition, Subtraction, Multiplication and Division of binary numbers are given below:
Addition Subtraction Multiplication Division
(i) 0+0=0 0-0=0 0x0=0 0/1=0
(ii) 0+1=1 1-0=1 0x1=0 1/1=1
(iii) 1+0=1 1-1=0 1x0=0 0/0=not allowed
(iv) 1+1=10 10-1=1 1x1=1 1/0=not allowed
Binary Addition: Two binary numbers can be added in the same way as two decimal numbers are added. The addition is carried out from the least significant bits and it proceeds to higher significant bits, adding the carry resulting from the previous addition each time. Consider the addition of the binary number 1010 and 1111.
Binary Decimal
A=1 1 1 1 15
B=1 0 1 0 10
-------------------- --------
A+B=11 0 0 1 25
--------------------- --------
Steps:
1. The least significant bits are added, i.e. 0+1=1 with a carry 0.
2. The carry in the previous step is added to the next higher significant bits, i.e. 1+1+0=0 with a carry 1.
3. The carry in the above step is added to the next higher significant bits, i.e. 0+1+1=0 with a carry 1.
4. The preceding carry is added to the most significant bits, i.e. 1+1+1=1 with a carry 1.
Binary Subtraction: Binary subtraction is also carried out in the same way as decimal numbers are subtracted. The subtraction is carried out from the least significant bits and proceeds to the higher significant bits. When 1 is subtracted from 0, a 1 is borrowed from the immediate higher significant bit.
Steps:
Case 1:
MSB LSB Decimal
1 1 0 1 13
1 0 0 1 9
---------- --------
0 1 0 0 4
---------- --------
1. The LSB in the first column are 1 and 1. Hence, the difference is 1-1=0.
2. In the second column, the subtraction is performed as 0-0=0.
3. In the third column, the difference is given by 1-0=1.
4. In the fourth column (MSB), the difference is given by 1-1=0.0
Case 2:
1
1 0 Decimal
1 0 0 1 9
0 1 1 1 7
---------- ------
0 0 1 0 2
---------- ------
The steps are described below.
1. The least significant bits in the first column are 1 and 1. Hence, the difference is 1-1=0.
2. In the second column, it is not possible to subtract the 1 from 0. So, a 1 has to be borrowed from the next MSB (3rd bit). But since the 3rd bit is also 0, borrowing has to be done from the MSB (4th bit). The borrowing of 1 from the 4th bit (with weight 8) results in 1 and 10 with weight 4 in the 3rd column and 0 in 4th column as shown above. Now, the subtraction is performed as 10-1=1.
3. In the third column, the difference is given by 1-1=0.
4. In the fourth column (MSB), the difference is given by 0-0=0.
Thus, the difference between the two binary numbers is 0010.
Binary Multiplication: Binary multiplication is much simpler than decimal multiplication. The procedure is same as that of decimal multiplication. The binary multiplication procedure is as follows:
1. The least significant bit of the multiplier is taken. If the multiplier bit is 1, the multiplication is copied as such and, if the multiplier bit is 0, a 0 is placed in all the bit positions.
2. The next higher significant bit of the multiplier is taken and the partial product is written with a shift to the left as in step 1.
3. Step 2 is repeated for all other higher significant bits and each time a left shift is given.
4. When all the bits in the multiplier have been taken into account, the partial product terms are added, which gives the actual product of the multiplier and the multiplicand.
Relationship between Decimal, Binary, Hexadecimal and Octal Number Systems
S.No.
|
Decimal
(Base=10)
|
Binary
(Base=2)
|
Octal
(Base=8)
|
Hexadecimal
(Base=16)
|
1.
|
0
|
0000
|
0
|
0
|
2.
|
1
|
0001
|
1
|
1
|
3.
|
2
|
0010
|
2
|
2
|
4.
|
3
|
0011
|
3
|
3
|
5.
|
4
|
0100
|
4
|
4
|
6.
|
5
|
0101
|
5
|
5
|
7.
|
6
|
0110
|
6
|
6
|
8.
|
7
|
0111
|
7
|
7
|
9.
|
8
|
1000
|
10
|
8
|
10.
|
9
|
1001
|
11
|
9
|
11.
|
10
|
1010
|
12
|
A
|
12.
|
11
|
1011
|
13
|
B
|
13.
|
12
|
1100
|
14
|
C
|
14.
|
13
|
1101
|
15
|
D
|
15.
|
14
|
1110
|
16
|
E
|
16.
|
15
|
1111
|
17
|
F
|