### Computer Arithmetic : Integer Arithmetic

All arithmetic operations in computer are done by addition and the same method of addition is used in the subtraction of two numbers. For example if the number 2 has to be subtracted from 4 (4-2), then it will executed as -2 added to 4 (-2+4). Because in binary system we have only two values 1 and 0 (or High and Low) to used for representing the arithmetic operations, therefore we are not allowed to use any third symbol for minus '-' sign representation. In binary we use one method of representing the negative number is the 2's compliment method. In this method a bit is reserved that does nothing but represent the mathematical sign. The most significant bit (MSB) is used for the representation of the sign bit. But first we need to look out how 2's compliment method works, and to understand 2's compliment we need to look 1's compliment :

1's Compliment :

The 1's compliment of any binary number can be found by converting 1's into 0's and 0's into 1's. For example the binary number (1010)2  (10 in decimal) 1's  compliment is :

Now the 1's compliment of 1010 is 101.

2's Compliment :

The 2's compliment of any number can be calculated by, first converting the binary number into it's 1's compliment and then adding 1 to the Least Significant Bit (LSB) of 1's compliment number. For example Lets calculate the 2's compliment of binary number (1101010)2 (106 in decimal) 2's :

Step 1 : 1's compliment of given binary number :

Step 2 : Add 1 to Least Significant Bit

Now the binary number 0010110 is the second compliment of 1101010.

Alternative Method For Finding 2's compliment :

The 2's compliment can also be found out by using alternative method. In this method Looking from LSB side, note all the digits till the first binary 1 is encountered, after that  1's compliment all rest of the digits, and the final number is 2's compliment of that number. For example lets try to find the 2's compliment of 11011100 by the alternative method :

Now we need to 1's compliment rest of the digits or bits which are underlined.

The 2's compliment of 11011100 is 100100

Signed Bit Binary Representation :

As we know we are not allowed to use any third symbol for minus '-' sign representation. So instead we are using the 2's compliment method to represent the negative numbers. In this method a bit is reserved that represent the mathematical sign. The most significant bit (MSB) is used for the representation of the sign bit. A ''0" in the sign bit place represents that the binary number is positive and a 1 represents negative number.

Below are the positive and negative number representations from 1 to 7.

The positive 5 is 0101 in signed binary number, its weightage can be calculated by adding the weightage of each binary digit i.e.

0 + 22 + 0 + 20 = 0 + 4 + 0 + 1 = 5

Similarly negative 5 is represented by binary number as 1011 which is 2's compliment of negative 3. the weightage of 1011 is

-23 + 0 + 21 + 20 = -8 + 0 + 2 + 1 = -5

Next Topic :