1s complement and 2s complement are way of representing the signed binary numbers.

In general, the binary number can be represented in two ways.

- Unsigned Binary Numbers
- Signed Binary Numbers

**Unsigned Binary Numbers**

Using unsigned binary number representation, only positive binary numbers can be represented. For n-bit unsigned binary numbers, all n-bits are used to represent the magnitude of the number.

For example, if we represent decimal 12 in 5- bit unsigned number form then (12)_{10} = (01100)_{2}. Here all 5 bit are used to represent the magnitude of the number.

In unsigned binary number representation, using n-bits, we can represent the numbers from 0 to 2^{n} – 1. For example, using 4 -bits we can represent the number from 0 to 15 in unsigned binary number representation.

**Signed Binary Numbers**

Using signed binary number representation both positive and negative numbers can be represented.

In signed binary number representation the most significant bit (MSB) of the number is a sign bit. For positive numbers, the sign bit is 0 and for negative number, the sign bit is 1.

There are three different ways the signed binary numbers can be represented.

- Signed Magnitude Form
- 1’s Complement Form
- 2’s Complement Form

**Sign Magnitude Representation**

In sign-magnitude representation, the Most Significant bit of the number is a sign bit and the remaining bit represents the magnitude of the number in a true binary form. For example, if some signed number is represented in the 8-bit sign-magnitude form then MSB is a sign bit and the remaining 7 bits represent the magnitude of the number in a true binary form.

Here is the representation of + 34 and -34 in a 8-bit sign-magnitude form.

Since the magnitude of both numbers is the same, the first 7 bits in the representation are the same for both numbers. For +34, the MSB is 0, and for -34, the MSB or sign bit is 1.

In sign magnitude representations, there are two different representations for 0.

Using n-bits, the range of numbers that can be represented in Sign Magnitude Representation is from **– (2 ^{n-1} – 1) to (2^{n -1} – 1)**.

**1’s Complement Representation**

In 1’s complement representation, the representation of the positive number is same as the negative number. But the representation of the negative number is different.

For example, if we want to represent -34 in 8-bit 1’s complement form, then first write the positive number (+34). And invert all 1s in that number by 0s and 0s by 1s in that number. The corresponding inverted number represents the -34 in 1’s complement form. It is also called 1s complement of the number +34.

Here is another example which shows how to represent -60 in 8-bit 1’s complement form.

Using n-bits, the range of numbers that can be represented in 1’s complement form is from ** – (2 ^{n-1} – 1) to (2^{n -1} – 1)**. For example, using 4-bits, it is possible to represent integers numbers from -7 to +7 in a 1’s complement form representation.

Similar to sign-magnitude form, there are two different representations of 0 in 1’s complement form representation.

**2’s Complement Representation**

In 2’s complement representation also, the representation of the positive number is same as1’s complement and sign-magnitude form.

But the representation of the negative number is different. For example, if we want to represent -34 in 2’s complement form then

- Write the number corresponding to +34.
- Starting from Least Significant Bit (LSB), just copy all the bits until the first 1 is encountered in the number.
- After the first ‘1’ is encountered, invert all the 1s in the number with 0s and 0s in the number with 1s (including the sign bit)
- The resultant number is 2’s complement representation of the number -34.

The same is shown below.

The second way of representing -34 in 2’s complement form is

- Write the number corresponding to +34.
- Find 1’s complement of +34
- Add ‘1’ to the 1’s complement number
- The resultant is 2’s complement representation of -34

The same is shown below.

For n-bit number N, its 2’s complement is (2^{n} – N). For example, the 2’s complement of +34 in 8-bit form is (2^{8 } – 34). In binary, it is 100000000 – 00100010 = 11011110. That is a third way of finding the 2’s complement.

Here is the representation of -60 in sign-magnitude form, 1’s complement, and 2’s complement form.

Using n-bits, the range of number which can be represented in 2’s complement form is from – (2^{n-1} ) to 2^{n-1} – 1. For example, using 4-bits, it is possible to represent numbers from -8 to +7. Unlike 1’s complement and sign magnitude form, there is a unique way of representing 0 in this 2’s complement form.

For information about signed binary number representation, check this video: