# Subtraction of signed binary numbers using 2’s Complement

In this article, we will perform a subtraction using 2’s complement. An unsigned binary number does not have a sign bit in the most significant bit (MSB) position. For example, consider 8-bit representation of 3810

\begin{aligned}
&38_{10} = 0010110_2\\\\
&=0 \cdot 2^7 + 0 \cdot 2^6 + 1 \cdot 2^5 + 0 \cdot 2^4 + 0 \cdot 2^4 + 0 \cdot 2^3 + 1 \cdot 2^2 + 1 \cdot 2^1 + 0 \cdot 2^0\\\\
&= 0 + 0 + 32 + 0 + 0 + 4 + 2 + 0\\\\
&=32 + 6\\\\
&=38_{10}\end{aligned}

Now, if we take two’s complement of unsigned binary number then we get signed binary representation of a number which is nothing but negative equivalent the unsigned binary number.

To understand this in an easy way, consider previous example of 3810. Let us convert the number 3810 into binary.

38_{10} = 0 0 1 0 0 1 1 0

Take 1’s complement of each binary digit in above number. That is, 0 becomes 1 and 1 becomes 0.

1's \hspace{3px} complement \hspace{3px} of \hspace{3px} 38 = 1 1 0 1 1 0 0 1

Adding 1 to the 1’s complement of 3810 we get two’s complement of the binary number.

\begin{aligned}
&\hspace{1cm}1\\
&1 1 0 1 1 0 0 1\\
& +\hspace{21px}1\\
&---------\\
& 1 1 0 1 1 0 1 0
\end{aligned}

The Most Significant Bit (MSB) has 1 which shows that it is a negative number. The resultant number is -3810

### Subtraction using 2’s Complement of unsigned binary number

Two’s complement of binary number is used for subtraction between unsigned and signed binary numbers.

For example,

How do we subtract?  -34 – (-45) = -34 + 45 = 11

Step 1:  Convert +34 in 2’s Complement form.

34 = 0 0 1 0 0 0 1 0

Obtain 1’s complement of 0 0 1 0 0 0 1 0

\begin{aligned}
&0 0 1 0 0 0 1 0\\
&+\hspace{21px}1\\
&-----\\
&0 0 1 0 0 0 1 1 = -34_{10}
\end{aligned}

Note:  The above step is only performed to obtain the -34 values. There are other methods to obtain negative signed values

Step 2:  Convert -45 into 2’s complement to find +45.

But we can also do it directly.

\begin{aligned}
&45 = 0 0 1 0 1 1 0 1\\
&= 0. 2^7 + 0. 2^6 + 1. 2^5 + 0. 2^4 + 1. 2^3+ 1. 2^2 + 0. 2^1 + 1. 2^0\\
&= 0 + 0 + 32 + 0 + 8 + 4 + 0 + 1\\
&= 32 + 8 + 4 + 1\\
&=45
\end{aligned}

Step 3:  Add binary value of -34 and 45

\begin{aligned}
&1 1 0 1 1 1 1 0   = -34\\
& 0 0 1 0 1 1 0 1   = +45\\
&----------\\
&0 0 0 0 1 0 1 1 = 1 1 _{1 0}

\end{aligned}

## Example Problems

Q 1: Perform the subtraction with the unsigned binary numbers by taking the 2’s complement of the subtrahend.

Source: Computer System Architecture by Morris Mano

a) 1 1 0 1 0 – 1 0 0 0 0

Solution:

Given

\begin{aligned}
&0001 1 0 1 0 = + 26\\
&0001 0 0 0 0 = + 16\\\\
&Take \hspace{5px}1's \hspace{5px}complement \hspace{5px}of \hspace{5px}000 1 0 0 0 0\\\\
&=11 1 0 1 1 1 1\\\\
&Add \hspace{5px}+1 \hspace{5px}to \hspace{5px}get \hspace{5px}2's \hspace{5px}complement \hspace{5px}of \hspace{5px}+ 16\\\\
&11101111\\
&+\hspace{21px}1\\
&---------\\
&111 1 0 0 0 0 = -16\\\\
&Add \hspace{5px}the \hspace{5px}binary \hspace{5px}value \hspace{5px}of \hspace{5px}+26 \hspace{5px}and \hspace{5px}-16\\
&1\\
&000 1 1 0 1 0 = +26\\
&111 1 0 0 0 0 = -16\\
&-------------\\
&000 0 1 0 1 0 = +10
\end{aligned}

b) 1 1 0 1 0 – 1 1 0 1

Solution:

Given

\begin{aligned}
&0 0 0 1 1 0 1 0 = +26\\
&0 0 0 0 1 1 0 1 = +13\\\\
&Take \hspace{5px} 1's \hspace{5px} complement \hspace{5px} of \hspace{5px}+13 \\\\
&= 0 0 0 0 1 1 0 1\\
&= 1 1 1 1 0 0 1 0\\\\
&Add \hspace{5px} 1 \hspace{5px} to\hspace{5px}  get \hspace{5px} 2's \hspace{5px} complement \hspace{5px} of \hspace{5px} +13\\\\
&1 1 1 1 0 0 1 0 \\
&+\hspace{21px}1\\
&-----------\\
& 1 1 1 1 0 0 1 1\\\\
&Add \hspace{5px} binary \hspace{5px} values \hspace{5px} of \hspace{5px} +26 \hspace{5px} and \hspace{5px} -13 to get the result.\\\\
&\hspace{21px} 1  \\
&0 0 0 1 1 0 1 0 = +26\\
&1 1 1 1 0 0 1 1 = -13\\
&----------\\
&0 0 0 0 1 1 0 1 = 13
\end{aligned}

c) 100 – 110000

Solution:

\begin{aligned}
&0 0 0 0 0 1 0 0 = +4\\
&0 0 1 1 0 0 0 0 = +48\\\\
&Take 1's complement of 48\\\\
&= 1 1 0 0 1 1 1 1\\\\
&Add \hspace{5px}1 \hspace{5px}to\hspace{5px} get \hspace{5px}the \hspace{5px}2's \hspace{5px}complement \hspace{5px} of \hspace{5px}+ 48\\\\
&\hspace{18px}  1 1 1 1 \\
&0 1 1 0 1 1 1 1 = +48\\
&+\hspace{21px}1 \\
&----------\\
&0 1 1 1 0 0 0 0\\\\
&Add \hspace{5px} the \hspace{5px}binary \hspace{5px}values \hspace{5px}of \hspace{5px}+4 \hspace{5px}and \hspace{5px}-48 \hspace{5px} to\hspace{5px} get \hspace{5px}the \\ \hspace{5px}
&0 0 0 0 0 1 0 0 = +04\\
&1 1 0 1 0 0 0 0 = -48\\
&----------\\
&1 1 0 1 0 1 0 0 = -44
\end{aligned}

d) 1010100 – 1010100

Solution:

\begin{aligned}
& 0 1 0 1 0 1 0 0 = 64 + 16 + 4 = +84\\
& 0 1 0 1 0 1 0 0 = 64 + 16 + 4 = +84\\\\
&Take \hspace{5px}1's \hspace{5px}complement \hspace{5px}of \hspace{5px}+84 \hspace{5px}subtrahend\\\\
&= 1 0 1 0 1 0 1 1\\\\
&Add \hspace{5px} 1 \hspace{5px} to \hspace{5px} get \hspace{5px} the \hspace{5px}2's \hspace{5px}complement \hspace{5px} of \hspace{5px}+84\hspace{5px} subtrahend\\\\
&\hspace{29px}1\\
&1 0 1 0 1 0 1 1\\
&+ \hspace{21px}1\\
&-------\\
&10101100\\\\
&Add \hspace{5px}the \hspace{5px}binary \hspace{5px}values \hspace{5px}of\hspace{5px}+84 \hspace{5px}and \hspace{5px}-84 \hspace{5px}to \hspace{5px}get \hspace{5px}the \hspace{5px} result\\\\
&0 1 0 1 0 1 0 0\\
&1 0 1 0 1 1 0 0\\
&------\\
&0 0 0 0 0 0 0 0
\end{aligned}