Unit 2-Binary arithmetic.docx
Unit 2-Binary arithmetic.docx
two operands. Basic arithmetic operations like addition, subtraction, multiplication, and division, play
an important role in mathematics.
Binary Addition
The binary system consists of only two digits, 1 and 0. Most of the functionalities of the
computer system use the binary number system.
If the sum of 2 bits is greater than 1, we need to shift a column on the left. In decimal system, 1 + 1
1 0
= 2. Binary notation of 2 is 10 (1 x 2 + 0 x 2 ). So we keep 0 in the 1's column and shift (carry over)
1 to the 2's column.
Step 1: First consider the 1’s column, and add the one’s column,( 1+1 ) and it gives the
result 10 as per the condition of binary addition.
Step 2: Now, leave the 0 in the one’s column and carry the value 1 to the 2’s column.
1
101
(+) 101
————–
0
Step 3: Now add 10’s place, 1+( 0 + 0 ) = 1. So, nothing carries to the 4’s place and leave
the value 1 in the 10’s place
1
101
(+) 101
————-
10
Step 4: Now add the 100’s place ( 1 + 1 ) = 10. Leave the value 0 in the 100’s place and
carries 1 to the 1000’s place.
1
101
(+) 101
————-
1010
So, the resultant of the addition operation is 1010.
2. Consider another example addition of 11 to 13. Binary equivalent of 11 is 1011 and that of 13 is
1101.
1011
+ 1101
1. 1's col = 1 + 1 = 10. We keep 0 in 1's col and carry over 1 to 2's col.
2. 2's col = 1 + 0 + 1 (carry over) = (1 + 0) + 1 = 1 + 1 = 10. Once again we keep 0 in 2's col
and carry over 1 to 4's col.
3. 4's col = 0 + 1 + 1 (carry over) = (0 + 1) + 1 = 1 + 1 = 10. Keep 0 in 4's col and carry over 1 in
8's col.
4. 8's col = 1 + 1 + 1 (carry over) = (1 + 1) + 1 = 10 + 1 = 11. Keep 1 in 8's col and carry over 1
in 16's col.
Binary subtraction
Binary subtraction is one of the four binary operations, where we perform the subtraction method for
two binary numbers (comprising of only two digits, 0 and 1). This operation is similar to the basic
arithmetic subtraction. when we subtract 1 from 0, we need to borrow 1 from the next higher order
digit.
0–0=0
0 – 1 = 1 ( with a borrow of 1)
1–0=1
1–1=0
1010
(-) 101
Step 1: First consider the 1’s column, and subtract the one’s column,( 0 – 1 ) and it gives the
result 1 as per the condition of binary subtraction with a borrow of 1 from the 2’s place.
Step 2: After borrowed 1 from the 2’s column, the value 1 in the 2’s column is changed into
the value 0 and 1 borrow
1010
(-) 1 0 1
1
1010
(-) 1 0 1
——————
01
Step 4: Now subtract the values in 4’s (100 in binary) place. Borrow 1 from the 8’s(1000 in
binary) place ( 0 – 1 ) = 1.
1010
(-) 1 0 1
————
0101
0 10 0 10 Borrow
1 0 1 0
1 0 1
0 1 0 1
2. subtract 10 (10102) from 12 (11002)
Binary Multiplication
The operation performed while finding the binary product is similar to the conventional multiplication
method. The binary multiplication operation is actually a process of addition and shifting operation.
This process has to be continued until all the multiplier is done, and finally, the addition operation is
made. The multiplication of the binary numbers is done by multiplying the multiplicand with the
multiplier. It is noted that the multiplication by zero makes all the bits zero. The multiplication by 1
makes all the multiplicand value unchanged. Note that the binary product of the two binary numbers
1 and 1 is equal to 1 only. And no additional number is borrowed or carried forward in this operation.
The rules/Procedure of binary multiplication are:
0 × 0 = 0 Binary product of 0 and 0 is equal to 0
0×1=0 Binary product of 0 and 1 is equal to 0
1×0=0 Binary product of 1 and 0 is equal to 0
1×1=1 Binary product of 1 and 1 is equal to 1(No borrow or carry is applicable)
Consider an example of multiplying 1011 x 1101
1. 1011 * 1 (multiplier 1's col) = 1011
2. 1011 * 0 (multiplier 2's col) = 00000 (one zero appended at the end)
3. 1011 * 1 (multiplier 4's col) = 101100 (two zero’s appended at the end)
4. 1011 * 1 (multiplier 8's col) = 1011000 (three zero’s appended at the end)
5. Sum up. 1011 + 00000 + 101100 + 1011000 = 10001111
Binary Division
The division is probably one of the most challenging operations of the basic arithmetic operations. There are different ways to solve division problems
using binary operations. Long division is one of them and the easiest and the most efficient way.
1÷1 = 1
1÷0 = Meaningless
0÷1 = 0
0÷0 = Meaningless
Step 1: Consider the first two numbers in the dividend and compare with the divisor. Add the number 1 in the quotient place. Then subtract
the value, you get 1 as remainder.
Step 2: Then bring down the next number from the dividend portion and do the step 1 process again
Step 3: Repeat the process until the remainder becomes zero by comparing the dividend and the divisor value.
Step 4: In this example, after we get the remainder value as 0, we have zero left in the dividend portion, so bring that zero to the quotient
portion.
2. Consider another example, Solve using the long division method: 101101 ÷ 101
So, when we bring down the fourth bit of the dividend, it does not match with the divisor. In order to bring down the 5th and 6th bit of the dividend, add
two zeros in the quotient value. After division the resultant value is quotient value which is equal to 1001.
0 0 Not defined
0 1 0
1 0 Not defined
1 1 1
Complement Arithmetic
Complements are used in the digital computers in order to simplify the subtraction operation and for the logical manipulations. For
each radix-r system (radix r represents base of number system) there are two types of complements. If r is the base/radix of the
number system, then there are two types of complements that are possible, i.e., r's complement and (r-1)'s complement. The r's
complement is also known as Radix complement and (r-1)'s complement is known as Diminished Radix complement.
If the base of the number is 2, then we can find 1's and 2's complement of the number. Similarly, if the number is the octal number,
then we can find 7's and 8's complement of the number. The mostly used complements are 1's, 2's, 9's, and 10's complement.
To find (b-1)’s complement: Subtract each digit of the number from the largest number in the number system with
base .
To find (b)’s complement: Add 1 to the LSB of the resultant (b-1)’s complement.
According to the rule of (b-1)’s complement , the largest number in the binary number system for a given 5 digit
number is 11111. Subtracting 10101 from 11111 we get
1 1 1 1 1
1 0 1 0 1
0 1 0 1 0
Another way to find the 1's complement of a number is, by changing all 1's to 0's and all 0's to 1's. This is called as taking
complement or 1's complement.
2's(b’s) complement
The 2's complement of binary number is obtained by adding 1 to the Least Significant Bit (LSB) of 1's complement of the number.
9's(b-1)’s Complement
The 9's complement is used to find the subtraction of the decimal numbers. The 9's complement of a number is calculated by
subtracting each digit of the number by 9.
For example, consider a number 1423, and we want to find the 9's complement of the number. For this, we subtract each digit of
the number 1423 by 9. So, the 9's complement of the number 1423 is 9999-1423= 8576.
For example, consider a number 1423, and we want to find the 10's complement of the number.
For this, first we have to find the 9’s complement of 1423 (9999-1423) which is 8576. Adding 1 to 8576 gives the 10’s complement
of the given number. Hence 10’s complement of 1423 is 8576 + 1 =8577.
1’s complement subtraction is a method to subtract two binary numbers. This method allows subtraction of two binary
numbers by addition. The 1’s complement of a binary number can be obtained by replacing all 0 to 1 and all 1 to 0.
Consider an example
1.Subtract 110101 – 100101 using 1’s complement
Minued 110101
subtrahend 100101
Minued - 110101
010000
1’s complement of 1 1 0 1 0 1 is 0 0 1 0 1 0.
Minued - 110101
Since there is no carry over, the final result is the 1’s complement of 1 0 1 1 1 1.
(iii) If the final carry over of the sum is 1, it is dropped/neglected 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.
Consider an example
1.Subtract 110101 – 100101 using 2’s complement
Minued 110101
subtrahend 100101
Since no carry over generated the result is the two’s complement of the sum and it is negative.
The weighted codes are BCD, 8421, 6421, 4221, 5211, 3321 etc.
Weighted codes are used in:
a) Data manipulation during arithmetic operation.
b) For input/output operations in digital circuits.
c) To represent the decimal digits in calculators, volt meters etc.
Non-weighted or un-weighted codes are those codes in which the digit value does not depend upon their position i.e., each digit
position within the number is not assigned fixed value.
Examples of non-weighted codes are: Excess-3 code and gray code.
Non weighted codes are used in:
a) To perform certain arithmetic operations.
b) Shift position encodes.
c) Used for error detecting purpose.
Code converter
A code converter is a logic circuit that changes data presented in one type of binary code to another type of binary code.
The logical circuit which converts the binary code to equivalent gray code is known as binary to
gray code converter.
1. The MSB (Most Significant Bit) of the gray code will be exactly equal to the first bit (MSB) of
the given binary number.
2. The second bit of the gray code will be exclusive-or (XOR) of the first and second bit of the
given binary number.
3. The third bit of gray code will be equal to the exclusive-or (XOR) of the second and third bit of
the given binary number. Thus the binary to gray code conversion goes on.
Consider an example of converting a binary number 00110 to gray code. The steps involved in
conversion are:
1. The MSB is kept the same. As the MSB of the binary is 0, the MSB of the gray code will be 0
as well (first gray bit)
2. Next, take the XOR of the first and the second binary bit. The first bit is 0, and the second bit
is 0. The bits are same so the resultant gray bit will be 0 (second gray bit)
3. Next, take the XOR of the second and third binary bit. The second bit is 0, and the third bit is
1. The bits are different so the resultant gray bit will be 1 (third gray bit)
4. Next, take the XOR of third and fourth binary bit. The third bit is 1, and the fourth bit is 1. As
these are the same, the resultant gray bit will be 0 (fourth gray bit)
5. Lastly, take the XOR of the fourth and fifth binary bit. The fourth bit is 1, and the fifth bit is 0.
These bits are different so the resultant gray bit will be 1 (fifth gray bit)
6. Hence the result of binary to gray code conversion of 00110 is complete, and the equivalent
gray code is 00101.
0 0 1 1 0 Binary Code
⊕ ⊕ ⊕ ⊕ EX-OR Operation
0 0 1 0 1 Gray Code
1. The MSB of the binary number will be equal to the MSB of the given gray code.
2. To obtain the second binary bit, perform the EX-OR operation between the first bit or most
siginificant digit of binary to the second bit of the given gray code.
3. To obtain the successive third binary bit, perform the EX-OR operation between the second
bit of binary to the third bit of gray code and so on for the next successive binary bits
conversion to find the equivalent Gray code to binary conversion.
Consider an example of converting a gray code 00101 to binary. The steps involved in conversion are:
0 0 1 0 1 Gray Code
⊕ ⊕ ⊕ ⊕ Ex-OR Operation
0 0 1 1 0 Binary Code
Excess-3 Code
The excess-3 code is also called as XS-3 code. The excess-3 code is a non-weighted and self-
complementary BCD code used to represent the decimal numbers. This code plays an important role
in arithmetic operations because it resolves deficiencies encountered when we use the 8421 BCD
code for adding two decimal digits whose sum is greater than 9.
We can easily get an excess-3 code of a decimal number by simply adding 3 to each decimal digit.
And then we write the 4-bit binary number for each digit of the decimal number. We can find the
excess-3 code of the given binary number by using the following steps:
1. Find the decimal number of the given binary number.
2. Add 3 in each digit of the decimal number.
3. Find the binary code of each digit of the newly generated decimal number.
We can also add 0011 in each 4-bit BCD code of the decimal number for getting excess-3 code.
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
Consider an example to find the Excess 3 code for the Decimal number 31
Digit BCD
3 0011
1 0001
3 0011+0011 0110
1 0001+0011 0100