# What is the subtraction of binary numbers?

Binary numbers are subtracted by performing two’s complement on the subtrahend. Two’s complement is done through the following steps −

• Complement every digit. That is, change 1 to 0 and 0 to 1.
• Add 1 to the output.

The following example illustrates the subtraction operation of binary digits using the above-mentioned steps.

### Example: 11101011 - 01100110

The second value 01100110 is to be subtracted from the first value 11101011.

First apply two’s complement to the second value 01100110, i.e., follow the two steps as shown.

Step 1: 0 1 1 0 0 1 1 0
1 0 0 1 1 0 0 1 (change 1 to 0 and 0 to 1)
Step 2: 1 0 0 1 1 0 0 1
1 0 0 1 1 0 1 0 (resultant)
1
Then, add the resultant to the first value.
1 1 1 0 1 0 1 1 (first value)
+1 0 0 1 1 0 1 0 (resultant)
1 0 0 0 0 1 0 1(output)
ignore 1 1 1 1 1 1
The output is 10000101.

It can understand the process of subtracting smaller number from larger number. The Most Significant Bit (MSB) or the leftmost bit is set to 1 to indicate a negative number. The MSB is known as the sign bit. The remaining 7 bits are used to express the value.

The following are the steps to subtract a greater number from a smaller number −

• It can apply two’s complement to the smaller number.
• It is used to add the resultant value to the smaller number.
• It can change MSB to 0.
• It can apply two’s complement to the resulting number.

MSB indicates a negative value.

### Example: 10010101 – 10110100

Step 1: 1 0 1 1 0 1 0 0 (greater number)
0 1 0 0 1 0 1 1 (change 1 for 0 and 0 for 1)
0 1 0 0 1 0 1 1
0 1 0 0 1 1 0 0
1 1
Step 2: 1 0 0 1 0 1 0 1 (smaller number)
+0 1 0 0 1 1 0 0 (add the resultant value to smaller number)
1 1 1 0 0 0 0 1
1 1 1
Step 3: 1 1 1 0 0 0 0 1
0 1 1 0 0 0 0 1 (change MSB bit to 0)
Step 4: 0 1 1 0 0 0 0 1
1 0 0 1 1 1 1 0 (change 1 for 0 and 0 for 1)
1 0 0 1 1 1 1 0
+1
1 0 0 1 1 1 1 1
Output = 10011111 (MSB indicates a negative value)