# Binary Representation of Integers

AS we already know Binary number can be represented only by using 0’s and 1’s, but can not use the sign (-) to denote the negative number or sign (+) to denote the positive number. So it must be either 0 or 1. There are three methods to represent binary number. They are

1.  Sign and magnitude method
2.  One’s complement method
3.  Two’s complement method

Sign and magnitude method
In this method, first bit is considered as a sign bit. Here positive number starts with 0
and negative number starts with 1.

Example
25
25/2 = 12 1
12/2 = 6 0
6/2 = 3 0
3/2 = 1 1
1/2 = 0 1
So the binary number is (11001)2. If we take the size of the word is 1 byte, then the number 25 will be represented as
00011001 Suppose, if the number is -25, and then it will be represented as 10011001

One’s Complement Method
In this method, the positive number is represented as same as the binary number. If the number is negative, then we need to find one’s complement of a binary number. The one’s complement of a binary number will replace every 0 with 1 and vice- versa.

Example
(i) Represent 86 in one’s complement method (I byte representation)
86/2 =43 0
43/2 =21 1
21/2 =10 1
10/2 =5 0
5/2 =2 1
2/2 =1 0
1/2 =0 1
The binary number is 1010110 1 byte representation of number 86 is 01010110

Two’s Complement method
In this method, the positive number is represented as the binary number. If the number is negative, then we need to calculate two’s complement of a binary number. The two’s complement of a binary number is calculated by adding 1 to its one’s complement.

Example
(i) Represent 87 in two’s complement method (I byte representation)
87/2 =43 1
43/2 =21 1
21/2 =10 1
10/2 =5 0
5/2 =2 1
2/2 =1 0
1/2 =0 1

The binary number is 1010111
Hence, the 1 byte representation of number 86 is 01010111

(ii) Represent -54 two’s complement method (I byte representation)
54/2 =27 0
27/2 =13 1
13/2 =6 1
6/2 =3 0
3/2 =1 1
1/2 =0 1
The binary number is 110110
Hence, the 1 byte representation is 00110110
The given number is negative; hence we need to calculate two’s complement.
One’s complement of 00110110 is 11001001 (convert 1 into 0 and 0 into 1)