0% found this document useful (0 votes)
13 views13 pages

Unit 2-Binary arithmetic.docx

The document explains binary operations, including addition, subtraction, multiplication, and division, using binary numbers (0 and 1). It details the rules and procedures for each operation, providing examples for clarity. Additionally, it covers complement arithmetic, including 1's and 2's complements, and their applications in subtraction.

Uploaded by

Keerthana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Unit 2-Binary arithmetic.docx

The document explains binary operations, including addition, subtraction, multiplication, and division, using binary numbers (0 and 1). It details the rules and procedures for each operation, providing examples for clarity. Additionally, it covers complement arithmetic, including 1's and 2's complements, and their applications in subtraction.

Uploaded by

Keerthana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

The term “Binary Operation” represents the basic operations of mathematics that are performed on

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.

There are 3 basic rules for adding binary numbers:


0+0=0
0+1=1
1 + 1 = 10.

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.

Procedure for Binary Addition of Numbers

1.Consider an example of the binary addition: 101(2) + 101(2)


101
(+) 101

 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.

So, the resultant of the addition operation is 11000(2).


1011
+ 1101
11000(2)

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.

Binary subtraction is represented as:

 0–0=0
 0 – 1 = 1 ( with a borrow of 1)

 1–0=1
 1–1=0

Procedure for Binary Subtraction of numbers:


Consider an of example subtracting 5 from 10. Binary equivalent of 10 is 1010 and that of 5 is 101.

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

 Step 3: So, subtract the value in the 2’s (10 in binary)place, ( 0 – 0 ) = 0.

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

So, the resultant of the subtraction operation is 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

So the product is 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.

The main rules of the binary division include:

 1÷1 = 1
 1÷0 = Meaningless
 0÷1 = 0
 0÷0 = Meaningless

Consider an example of dividing 01111100 by 0010


In the given example dividend is 01111100, and the divisor is 0010
Remove the zero’s in the Most Significant Bit in both the dividend and divisor, that doesn’t change the value of the number.
So the dividend becomes 1111100, and the divisor becomes 10.The steps involved by using the long division method are

 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.

Therefore, the resultant value is quotient value which is equal to 111110.

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.

Input A Input B Divide (D)


A/B

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.

Binary system complements


As the binary system has base r = 2. So the two types of complements for the binary system are 2's complement and 1's
complement.

1's (b-1)’s complement


Consider an example to find the complement of 10101

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.

Example of 1's Complement is as follows.

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.

2's complement = 1's complement + 1

Example of 2's Complement is as follows.

Decimal system complements


As the decimal system has base r = 10. So the two types of complements for the binary system are 10's complement and 9's
complement.

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.

Similarly, 9’s complement of 25 is 99-25=74


10’s (r’s) Complement
It is relatively easy to find out the 10’s complement after finding out the 9’s complement of that number. We have to add 1 with
the 9’s complement of any number to obtain the desired 10’s complement of that number.

10's complement = 9's complement + 1

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 method

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.

The steps to be followed in subtraction by 1’s complement are:

i) To write down 1’s complement of the subtrahend.


ii) To add this with the minuend.
iii) If the result of addition has a carry over then it is dropped/neglected and an 1 is added in the last 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.

Consider an example
1.Subtract 110101 – 100101 using 1’s complement
Minued 110101
subtrahend 100101

1’s complement of 100101 is 011010. Hence

Minued - 110101

1’s complement of subtrahend - 011010


Carry over - 1 001111

010000

Hence the difference of 110101 – 100101 is 010000

2.Subtract 100101 – 110101 using 1’s complement


Minued 100101
subtrahend 110101

1’s complement of 1 1 0 1 0 1 is 0 0 1 0 1 0.

Minued - 110101

1’s complement of subtrahend - 011010


101111

Since there is no carry over, the final result is the 1’s complement of 1 0 1 1 1 1.

Hence the difference of 100101 – 110101 is -010000


Subtraction using 2’s complement method

The operation is carried out by means of the following steps:

(i) At first, 2’s complement of the subtrahend is found.

(ii) Then it is added to the minuend.

(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

2’s complement of subtrahend is given by 1’s complement of subtrahend + 1

2’s complement of 100101 is 011010


+ 1
011011

Hence, Minued - 110101

2’s complement of subtrahend - 011011


Carry over - 1 010000

The carry generated is neglected and the result is positive.

Hence the difference of 110101 – 100101 is 010000

2. Subtract 100101 – 110101 using 2’s complement


Minued 100101
subtrahend 110101

2’s complement of subtrahend is given by 1’s complement of subtrahend + 1

2’s complement of 110101 is 001010


+ 1
001011

Hence, Minued - 100101

2’s complement of subtrahend - 001011


No Carry over 110000

Since no carry over generated the result is the two’s complement of the sum and it is negative.

Hence the result is 2’s complement of 110000 is 001111


+ 1
010000

Hence the difference of 100101 – 110101 is - 010000

Weighted and non-weighted codes


In weighted code, each digit position has a weight or value. The sum of all digits multiplied by a weight gives the total value
being represented.
We can express any decimal number in tens, hundreds and thousands.
Example: Decimal number 3675 can be written as
3675 = 3000+600+70+5
In the power of 10, it becomes
3 2 1 0
3675 = 3 x 10 + 6 x 10 +7 x 10 + 5 x 10

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.

Binary to Gray code Conversion


Gray code is also known as Cyclic Code, Reflected Binary Code (RBC) and is defined as an
ordering of the binary number system such that each incremental value can only differ by one bit. In
gray code, while traversing from one step to another step only one bit in the code group changes.
That is , two adjacent code numbers differ from each other by only one bit.It is the most popular of
the unit distance codes, but it is not suitable for arithmetic operations. Some of the applications of
Gray code are:
 used in analog to digital converters
 used for error correction in digital communication.

The logical circuit which converts the binary code to equivalent gray code is known as binary to
gray code converter.

Steps involved in Converting Binary to Gray Code

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

Gray to Binary code Conversion


The logical circuit which converts the gray code to equivalent binary code is known as gray to
binary code converter.

Steps involved in Converting Gray Code to Binary Conversion

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:

1. The MSB of the binary will be 0 as the MSB of gray is 0.


2. To obtain the second binary bit , perform EX-OR operation between the first bit or MSB of
the binary 0 with the second bit 0 of the gray code. The second binary bit will be 0 ( 0 ⊕ 0 =
0).
3. To obtain the third binary bit , perform EX-OR operation between the second binary bit 0
with the third bit 1 of the gray code. Hence the third binary bit will be 1 ( 0 ⊕ 1 = 1).
4. To obtain the fourth binary bit , perform EX-OR operation between the third binary bit 1
with the fourth bit 0 of the gray code. Hence the fourth binary bit will be 1 ( 1 ⊕ 0 = 1).
5. To obtain the fifth binary bit , perform EX-OR operation between the fourth binary bit 1
with the fifth bit 1 of the gray code. Hence the fourth binary bit will be 0 ( 1 ⊕ 1 = 0).
6. Hence the result of gray code to binary conversion of 00101 is complete, and the equivalent
binary code is 00110.

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.

The Excess-3 code for the decimal number is as follows:

Decimal Digit BCD Code 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

1. We find the BCD code of each digit of the decimal number.

Digit BCD

3 0011

1 0001

2) Then, we add 0011 in both of the BCD code.


Decimal BCD Excess-3

3 0011+0011 0110

1 0001+0011 0100

3. So, the excess-3 code of the decimal number 31 is 0110 0100

The advantages of excess-3 code are:

1. These codes are usually un weighted binary decimal codes.


2. These codes are self-complementary.
3. The excess-3 code has no limitation, so that it considerably simplifies arithmetic operations.
4. The codes 0000 and 1111 can cause a fault in the transmission line. The excess-3 code doesn't use these codes and gives
an advantage for memory organization.
5. This code has a vital role in arithmetic operations because it resolves deficiencies which are encountered when we use
the 8421 BCD code for adding two decimal digits whose sum is greater than 9.

You might also like