There are three ways to represent integers in computer.
They are as follows:
1) Sign Magnitude Representation (SMR)
2) 1’s Complement Representation
3) 2’s Complement Representation .
(1) SMR : Normally a number has: two parts sign and magnitude,
eg:- Consider a number +5. Here + is the sign and 5 is the magnitude. In SMR the most significant Bit (MSB) is used to represent the sign. If MSB is 0 sign is +ve and MSB is 1 sign is – ve.
Here MSB is used for sign then the remaining 7 bits are used to represent magnitude. So we can represent 27 = 128 numbers. But there are negative and positive numbers.
So 128 + 128 = 256 number. The numbers are 0 to + 127 and 0 to – 127. Here zero is repeated. So we can represent 256 – 1 = 255 numbers.
2) 1’s Complement Representation : To get the 1’s complement of a binary number, just replace every 0 with 1 and every 1 with 0. Negative numbers are represented using 1’s complement but + ve number has no 1’s complement,
eg:- To find the 1 ‘s complement of 21 +21 = 00010101
To get the 1 ‘s complement change all 0 to 1 and all 1 to 0.
– 21 = 11101010
1’s complement of 21 is 11101010
3) 2’s Complement Representation :
To get the 2’s complement of a binary number, just add 1 to its 1’s complement +ve number has no 2’s complement.
eg:- To find the 2’s complement of 21 +21 = 00010101
First lake the 1’s complement for this change all 1 to 0 and all 0 to 1
2’s complement of 21 is 1110 1011