# Binary Subtraction using 2’s Complement

There are a total of four binary operations; binary subtraction is one of them. The binary subtraction is carried out by applying the subtraction procedure to two binary values (numbers that only contain 0 and 1). The binary subtraction is similar to the fundamental subtraction performed in Maths on decimal numbers. Therefore, in order to reduce the digit by one, we must borrow one from the next higher-order digit when subtracting 1 from 0. The remaining digit is also 1.

The basic binary subtraction is given below:

• 0 – 0 = 0
• 1 – 0 = 1
• 1 – 1 = 0
• 0 – 1 = 1 (Borrow 1)

## Example of binary subtraction:

1010

-101

0101

2’s Complement Binary Subtraction

In 2’s complement binary subtraction in order to subtract two binary numbers, we add one number with the others 2’s complement. In order to get the 2’s complement of a binary number, the given number is simply inverted and 1 is added to the least significant bit (LSB) of the given result.

2's Complement of Positive Numbers is used to represent negative numbers. In binary form, for instance, -8 can be represented as 2's Complement of 8.

Step 1: The first step in putting this method for subtracting two binary numbers into practice is to find the 2’s complement of the number to be subtracted from another number.

For this, first we find the 1’s complement of the number and then add 1 to it in order to get the 2’s complement.

For example, let’ say we need to find the 2’s complement of the binary number 01001(9). We need to find its 1’s complement first. In order to find it, we substitute all 0 with 1 and all 1 with 0. Then 1 is added to it to get the 2’s complement. This is shown below:

Binary number: 0111
1’s complement: 1000
+1
2’s Complement : 1001
• For a negative number, we consider the binary numbers from 0000 to 1111 (base ten's 0 to 15).
• Respectively, the numbers (0001 – 0111) will represent the positive numbers 1 through 7, while (1001 – 1111) will represent the negative numbers -7 through -1.
• Numbers are stored in binary form in registers on a computer, where a specific number of bits are reserved for this purpose. There are various sizes of registers. For this example, we will use a register of size 8.
• Using two's complement, it is simple to convert a negative integer in base ten into binary form.
• First, ensure that the register you select is large enough to hold all of the bits required to represent the number.
• In binary form, write the given number's absolute value. If you put 0 before this number, it means that it is positive but if you put 1 before then it means it is negative.
• By changing zeros into ones and ones into zeros, you can get the complement of each bit.
• Then, add one to your outcome. The negative integer is represented here using the two's complement.

Example: Determine the 2’s complement of -17.

Binary number:  0001 0001
1’s complement: 1110 1110
+            1
2’s complement:  1110 1111

Therefore, here the binary number 1110 1111 is the 2’s complement for -17. Since it starts on the left with a 1, we know that it is a negative number.

Step 2: Add the 2’s complement of the smaller number to the larger number.

Step 3: Exclude the carry. Keep in mind that this case always has a carry.

Example: Subtract (1101)2 from (0111)2 using 2’s complement.

Step - 1: 2’s complement of (0111)2 is (1001)2.