Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Signed Binary Arithmetic



In this chapter, let us discuss about the basic arithmetic operations, which can be performed on any two signed binary numbers using 2s complement method. The basic arithmetic operations are addition and subtraction.

Addition of two Signed Binary Numbers

Consider the two signed binary numbers A & B, which are represented in 2s complement form. We can perform the addition of these two numbers, which is similar to the addition of two unsigned binary numbers. But, if the resultant sum contains carry out from sign bit, then discard (ignore) it in order to get the correct value.

If resultant sum is positive, you can find the magnitude of it directly. But, if the resultant sum is negative, then take 2s complement of it in order to get the magnitude.

Example 1

Let us perform the addition of two decimal numbers +7 and +4 using 2s complement method.

The 2s complement representations of +7 and +4 with 5 bits each are shown below.

$$\mathrm{(+7)_{10} \: = \: (00111)_{2}}$$

$$\mathrm{(+4)_{10} \: = \: (00100)_{2}}$$

The addition of these two numbers is

$$\mathrm{(+7)_{10} \: + \: (+4)_{10} \: = \: (00111)_{2} \: + \: (00100)_{2}}$$

$$\mathrm{\Rightarrow \: (+7)_{10} \: + \: (+4)_{10} \: = \: (01011)_{2}}$$

The resultant sum contains 5 bits. So, there is no carry out from sign bit. The sign bit 0 indicates that the resultant sum is positive. So, the magnitude of sum is 11 in decimal number system. Therefore, addition of two positive numbers will give another positive number.

Example 2

Let us perform the addition of two decimal numbers -7 and -4 using 2s complement method.

The 2s complement representation of -7 and -4 with 5 bits each are shown below.

$$\mathrm{(7)_{10} \: = \: (11001)_{2}}$$

$$\mathrm{(4)_{10} \: = \: (11100)_{2}}$$

The addition of these two numbers is

$$\mathrm{(7)_{10} \: + \: (4)_{10} \: = \: (11001)_{2} \: + \: (11100)_{2}}$$

$$\mathrm{\Rightarrow \: (7)_{10} \: + \: (4)_{10} \: = \: (110101)_{2}}$$

The resultant sum contains 6 bits. In this case, carry is obtained from sign bit. So, we can remove it

Resultant sum after removing carry is (7)10 + (4)10 = (10101)2.

The sign bit 1 indicates that the resultant sum is negative. So, by taking 2s complement of it we will get the magnitude of resultant sum as 11 in decimal number system. Therefore, addition of two negative numbers will give another negative number.

Subtraction of two Signed Binary Numbers

Consider the two signed binary numbers A & B, which are represented in 2s complement form. We know that 2s complement of positive number gives a negative number. So, whenever we have to subtract a number B from number A, then take 2s complement of B and add it to A. So, mathematically we can write it as

A - B = A + (2's complement of B)

Similarly, if we have to subtract the number A from number B, then take 2s complement of A and add it to B. So, mathematically we can write it as

B - A = B + (2's complement of A)

So, the subtraction of two signed binary numbers is similar to the addition of two signed binary numbers. But, we have to take 2s complement of the number, which is supposed to be subtracted. This is the advantage of 2s complement technique. Follow, the same rules of addition of two signed binary numbers.

Example 1

Let us perform the subtraction of two decimal numbers +7 and +4 using 2s complement method.

The subtraction of these two numbers is

$$\mathrm{(+7)_{10} \: \: (+4){10} \: = \: (+7)_{10} \: + \: (4)_{10}}$$

The 2s complement representation of +7 and -4 with 5 bits each are shown below.

$$\mathrm{(+7)_{10} \: = \: (00111)_{2}}$$

$$\mathrm{(+4)_{10} \: = \: (11100)_{2}}$$

$$\mathrm{\Rightarrow \: (+7)_{10} \: + \: (+4)_{10} \: = \: (00111)_{2} \: + \: (11100)_{2} \: = \: (00011)_{2}}$$

Here, the carry obtained from sign bit. So, we can remove it. The resultant sum after removing carry is

$$\mathrm{(+7)_{10} \: + \: (+4)_{10} \: = \: (00011)_{2}}$$

The sign bit 0 indicates that the resultant sum is positive. So, the magnitude of it is 3 in decimal number system. Therefore, subtraction of two decimal numbers +7 and +4 is +3.

Example 2

Let us perform the subtraction of two decimal numbers +4 and +7 using 2s complement method.

The subtraction of these two numbers is

$$\mathrm{(+4)_{10} \: \: (+7)_{10} \: = \: (+4)_{10} \: + \: (7)_{10}}$$

The 2s complement representation of +4 and -7 with 5 bits each are shown below.

$$\mathrm{(+4)_{10} \: = \: (00100)_{2}}$$

$$\mathrm{(-7)_{10} \: = \: (11001)_{2}}$$

$$\mathrm{\Rightarrow \: (+4)_{10} \: + \: (-7)_{10} \: = \: (00100)_{2} \: + \: (11001)_{2} \: = \: (11101)_{2}}$$

Here, carry is not obtained from sign bit. The sign bit 1 indicates that the resultant sum is negative. So, by taking 2s complement of it we will get the magnitude of resultant sum as 3 in decimal number system. Therefore, subtraction of two decimal numbers +4 and +7 is -3.

Advertisements