TITLE

# Two’s complement: Definition, Methods, and Examples

In mathematics, the two’s complement is widely used in a number system as well as in a machine language. The numbers of two’s complements are written in zeros and ones similar to the binary number system.

The two’s complement is generally used for the conversion of negative numbers in the form of zeros and ones. In this post, we will learn the definition, methods of conversion, and solved examples of two’s complements.

## What is the two’s complement?

In mathematics, the two’s complement is used to encode positive and negative numbers in the form of 0’s and 1’s. one’s complement can be used to encode positive numbers but it is very difficult to encode negative numbers using this. So, the two’s complement is created.

The two’s complement is an example of a radix complement. It can also encode and convert the binary number system and decimal number system. It is generally a mathematical operation that is frequently used in the number system.

One’s complement is the inversion of the binary number system as all the zeros are inverted into ones and vice versa. While the two’s complement is calculated by adding one to the least significant bit of one’s complement or inverted binary number.

## Conversion of binary & decimal number system into two’s (2’s) complement

Follow the below procedure for the conversion of the decimal and binary numbers systems into two’s complement.

### 1.   Conversion of Binary to two’s (2’s) complement

Here are a few steps to find the two’s complement of a binary number.

• First of all, Take a binary number in the form of zero’s & one’s.
• After that invert all the digits of the given binary numbers such as all the 0’s into 1’s and vice versa. The inversion of numbers is also known as taking the transpose.
• In the end, add 1 to the least significant bit of the transpose of the binary number to get the result of two’s (2’s) complement.

By following the above steps, you are able to find the two’s complement of a binary number manually. Below are a few examples of the conversion of binary numbers into two’s complement.

Example 1

Convert the binary number “10011111001” into two’s (2’s) complement.

Solution

Step 1: Take the given binary number.

10011111001

Step 2: Now invert all the digits of the given binary number.

01100000110

Step 3: Add 1 to the LSB (least significant bit) of the above-inverted numbers.

0 1 1 0 0 0 0 0 1 1 0

+ 1

0 1 1 0 0 0 0 0 1 1 1

Hence,

The two’s complement of “1001111001” is “01100000111”

Example 2

Convert the binary number “11110000001111” into two’s (2’s) complement.

Solution

Step 1: Take the given binary number.

11110000001111

Step 2: Now invert all the digits of the given binary number.

00001111110000

Step 3: Add 1 to the LSB (least significant bit) of the above-inverted numbers.

0 0 0 0 1 1 1 1 1 1 0 0 0 0

+ 1

0 0 0 0 1 1 1 1 1 1 0 0 0 1

Hence,

The two’s complement of “11110000001111” is “00001111110001”

Table of some binary numbers to two’s complement

### 2.   Conversion of decimal to two’s (2’s) complement

Here are a few steps to find the two’s complement of positive and negative decimal numbers.

For positive number

• Take a positive decimal number i.e., 12, 34, 45, etc.
• Convert the given positive number into a binary number system.
• After that invert all the digits of the calculated binary numbers such as all the 0’s into 1’s and vice versa. The inversion of numbers is also known as taking the transpose.
• In the end, add 1 to the least significant bit of the transpose of the binary number to get the result of two’s (2’s) complement.

For negative number

• Take a negative decimal number i.e., -12, -34, -67, etc.
• Find the two’s (2’s) complement of the given number with a positive sign.
• After finding the two’s complement of positive numbers invert all the digits of that result such as all the 0’s into 1’s and vice versa. The inversion of numbers is also known as taking the transpose.
• In the end, add 1 to the least significant bit of the transpose of the binary number to get the result of two’s (2’s) complement.

A two’s complement calculator can be used to find the 2’s complement of positive and negative numbers according to the above steps.

Below are a few examples of the conversion of decimal numbers into two’s complement.

Example I: For a positive decimal number

Convert 194 into two’s (2’s) complement.

Solution

Step I: Write the given positive decimal number.

194

Step II: Now convert 194 into two’s complement.

Hence the binary number of 194 is (11000010)2

Step III: Now invert all the digits of the given binary number.

00111101

Step IV: Now add 1 to the least significant bit (LSB) of one’s (1’s) complement.

0 0 1 1 1 1 0 1

+ 1

0 0 1 1 1 1 1 0

Hence,

The two’s (2’s) complement of 194 is 00111110

Example II: For a negative decimal number

Convert -191 into two’s (2’s) complement.

Solution

Step I: Write the given negative decimal number.

-191

Now Find the two’s complement according to the positive number 191.

Step II: Now convert 191 into two’s complement.

Hence the binary number of 191 is (10111111)2

Step III: Now invert all the digits of the given binary number.

01000000

Step IV: Now add 1 to the least significant bit (LSB) of one’s (1’s) complement.

0 1 0 0 0 0 0 0

+ 1

0 1 0 0 0 0 0 1

Hence,

The two’s (2’s) complement of 191 is 01000001.

Step V: Now treat the two’s complement of 191 as a binary number and apply the procedure of binary to two’s complement to find the two’s complement of the negative decimal number.

01000001 becomes 10111110 after inverting.

Step VI: Now add 1 to the least significant bit (LSB) of one’s (1’s) complement.

1 0 1 1 1 1 1 0

+ 1

1 0 1 1 1 1 1 1

Hence the 2’s complement of -132 is 1000100.

Table of some decimal numbers to two’s complement

## Conclusion

In this post, we have discussed all the basics of the two’s complement along with the definition, methods, and examples. Now you can solve any problem of the two’s complement easily by following the above post.