Contents

## The Two’s Complement Definition, Steps of Conversion with Examples.

In number theory, the two’s (2s) complement is frequently used in machine languages to encode various terms. The representation of the two’s (2s) complement is similar to the binary variables such as 0 & 1.

The one’s complement is used to convert the positive numbers in the form of 0 & 1. But it is not applicable for the negative numbers, so the 2s complement is created. In this post, we are going to explore definition of Two’s complement and procedure of converting decimal numbers or binary number into 2s complement in step wise. Also provided here examples and online two’s complement converter.

### Two’s Complement ( 2s complement) – Definition

In mathematics, to encode the positive and negative numbers in the form of 0 & 1, the two’s complement is used. On the other hand, the one’s complement is also used to encode the numbers in the form of binary variables.

But it is only suitable for encoding positive numbers. So, the 2s complement is created for especially encoding the negative numbers. It is an example of a radix complement. In a number system, the 2’s complement is an operation that involves the binary variable.

As we know that the one’s complement is the transpose of binary variables as it inverts the o’s into 1’s and 1’s into 0’s. On the other hand, the two’s complement is determined by adding 1 to the LSB (least significant bit) of the transpose of the binary variables.

### Turning various number systems into twos Complement

To turn the binary and decimal numbers system into twos complement follow the below procedure.

#### Turning Binary numbers into 2s complement

Follow the below steps to turn a binary number system into 2s complement.

**a)** First of all, take a binary variable number in the form of 0 & 1.

**b)** Take the transpose of the binary number system as inverting all the zeros into ones and vice versa. This process of inverting the binary variables is referring to 1s complement.

**c)** To get the two’s complement, add one to the last digit of the one’s complement.

The above three steps are helpful in turning the binary number system into two’s complement without any difficulty. Let us take some examples of this conversion to understand the concept more accurately.

**Example I : **Turn the given binary number into a 2s complement – 1111 0000 1110

**Solution**

**Step-1:** First of all, take a binary variable.

1111 0000 1110

**Step-2:** Take the transpose of the 1111 0000 1110 as inverting all the zeros into ones and vice versa.

0000 1111 0001

**Step-3:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

**The 2s complement of “1111 0000 1110 ” is “0000 1111 0010”**

**Example II : **Turn the given binary number into a 2s complement – 0101 0101

**Solution**

**Step-1:** First of all, take a binary variable.

0101 0101

**Step-2:** Take the transpose of the 0101 0101 as inverting all the zeros into ones and vice versa.

1010 1010

**Step-3:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

1 0 1 0 1 0 1 0

__ + 1__

1 0 1 0 1 0 1 1

Hence,

**The 2s complement of “0101 0101” is “1010 1011”**

#### Turning decimal numbers into 2s complement

Follow the below steps to turn a decimal number system into *two’s complement.*

**For a positive decimal number**

**a)** First of all, take a positive decimal i.e., 102, 304, 415, etc.

**b)** Turn the positive decimal number system into the form of binary variables.

**c) **Take the transpose of the binary number system as inverting all the zeros into ones and vice versa. This process of inverting the binary variables is referring to 1s complement.

**d) **To get the two’s complement, add one to the last digit of the one’s complement.

**For a negative decimal number **

**a)** First of all, take a negative decimal i.e., -11, -4, -45, etc.

**b)** Find the 2s complement of the number without a negative sign by following the above four steps.

**c)** After that take the transpose of the 2s complement of the positive number as inverting all the zeros into ones and vice versa.

**d)** To get the two’s complement, add one to the last digit of the one’s complement.

The above four steps of positive and negative decimal numbers are helpful in turning the decimal number system into a 2s complement without any difficulty. Let us take some examples of this conversion to understand the concept more accurately.

**Example III: **** For a positive and negative decimal number**

Convert the given decimal numbers into 8-bit 2s complement. a) 120 b ) -115

** a) 120
**

**Solution:**

**Step-I: **First of all, take a 8-bit positive decimal. 120

**Step-II:** Now turn 120 in the form of binary variables.

__2 | 120__

__2 | 60 – 0 __

__2 | 30 – 0 __

__2 | 15 – 0 __

__2 | 7 – 1 __

__2 | 3 – 1 __

1 – 1

Hence,

120 = (1 1 1 1 0 0 0 )_{2}

Completing the 8-bit of the above binary number.

120 = (0 1 1 1 1 0 0 0)_{2}

**Step-III:** Take the transpose of the 0 1 1 1 1 0 0 0 as inverting all the zeros into ones and vice versa.

1 0 0 0 0 1 1 1

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

1 0 0 0 0 1 1 1

__ + 1__

1 0 0 0 1 0 0 0

Hence,

**1000 1000 is the 2s complement of 120.**

**b) -115**

**Solution **

**Step-I: **First of all, take a negative decimal number. -115

Let’s calculate the 2s complement of positive 115.

**Step-II:** Now turn 115 in the form of binary variables.

__2 | 115__

__2 | 57 – 1 __

__2 | 28 – 1 __

__2 | 14 – 0 __

__2 | 7 – 0 __

__2 | 3 – 1 __

1 – 1

Hence,

115 = (0 1 1 1 0 0 1 1)_{2} in 8 -bit representation

**Step-III:** Take the transpose of the 0 1 1 1 0 0 1 1 as inverting all the zeros into ones and vice versa.

1 0 0 0 1 1 0 0

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

1 0 0 0 1 1 0 0

__ + 1__

1 0 0 0 1 1 0 1

Hence,

**1000 1101** is the 2s complement of 115.

**Step-V:** Now invert the two’s complement of positive decimal number.

1 0 0 0 1 1 0 1 becomes 0 1 1 1 0 0 1 0 after inverting.

**Step VI:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

0 1 1 1 0 0 1 0

__ + 1__

0 1 1 1 0 0 1 1

Hence,

**0111 0011 is the 2s complement of -115.**

**Example IV: **** For a positive and negative decimal number**

Convert the given decimal numbers into 12-bit 2s complement. a) 257 b ) -357

** a) 257
**

**Solution:**

**Step-I: **First of all, take a 12-bit positive decimal. 257

**Step-II:** Now turn 257 in the form of binary variables.

__2 | 257__

__2 | 128 – 1 __

__2 | 64 – 0 __

__2 | 32 – 0 __

__2 | 16 – 0 __

__2 | 8 – 0 __

__2 | 4 – 0 __

__2 | 2 – 0 __

1 – 0

Hence,

257 = (100000001)_{2}

Completing the 12-bit of the above binary number.

257 = (000100000001)_{2}

**Step-III:** Take the transpose of the 000100000001 as inverting all the zeros into ones and vice versa.

111011111110

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

**1110 1111 1111 is the 2s complement of 257.**

**b) -357**

**Solution **

**Step-I: **First of all, take a negative decimal number. -357

Let’s calculate the 2s complement of positive 357.

**Step-II:** Now turn 357 in the form of binary variables.

__2 | 357__

__2 | 178 – 1 __

__2 | 89 – 0 __

__2 | 44 – 1 __

__2 | 22 – 0 __

__2 | 11 – 0 __

__2 | 5 – 1 __

__2 | 2 – 1 __

1 – 0

Hence,

357 = (000101100101)_{2} in 12-bit representation

**Step-III:** Take the transpose of the 000101100101 as inverting all the zeros into ones and vice versa.

1110 1001 1010

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

1110 1001 1011 is the 2s complement of 357.

**Step-V:** Now invert the two’s complement of positive decimal number.

1110 1001 1011 becomes 0001 0110 0100 after inverting.

**Step VI:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

**0001 0110 0101 is the 2s complement of -357.**

**Example V : **** For a positive and negative decimal number**

Convert the given 16-bit decimal numbers into 2s complement. a) 257 b ) -357

** a) 257
**

**Solution:**

**Step-I: **First of all, take a 12-bit positive decimal. 257

**Step-II:** Now turn 257 in the form of binary variables.

__2 | 257__

__2 | 128 – 1 __

__2 | 64 – 0 __

__2 | 32 – 0 __

__2 | 16 – 0 __

__2 | 8 – 0 __

__2 | 4 – 0 __

__2 | 2 – 0 __

1 – 0

Hence,

257 = (100000001)_{2}

Completing the 16-bit of the above binary number.

257 = (0000000100000001)_{2}

**Step-III:** Take the transpose of the 000100000001 as inverting all the zeros into ones and vice versa.

1111111011111110

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

**1111 1110 1111 1111 is the 2s complement of 257.**

**b) -357**

**Solution **

**Step-I: **First of all, take a negative decimal number.

-357

Let’s calculate the 2s complement of positive 357.

**Step-II:** Now turn 357 in the form of binary variables.

__2 | 357__

__2 | 178 – 1 __

__2 | 89 – 0 __

__2 | 44 – 1 __

__2 | 22 – 0 __

__2 | 11 – 0 __

__2 | 5 – 1 __

__2 | 2 – 1 __

1 – 0

Hence,

357 = (0000000101100101)_{2} in 16-bit representation

**Step-III:** Take the transpose of the 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 as inverting all the zeros into ones and vice versa.

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

**Step-IV:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

1 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 is the 2s complement of 357.

**Step-V:** Now invert the two’s complement of positive decimal number.

1 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 becomes 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 0 after inverting.

**Step VI:** Now To get the two’s complement, add one to the last digit of the above inverted binary number.

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

__ + 1__

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

Hence,

**0000 0001 0110 0101 is the 2s complement of -357.**

#### Online calculator for binary or decimal value to two’s complement

Click Here 2s complement calculator

**Conclusion:**

In this article, we have covered all the basic intent of the *twos complement*. We discussed the definition and inversion of binary and decimal numbers system into 2s complement along with solved examples. Now you can learn all the basics of the 2s complement from this post.

**Related Articles:**

Shortcut to Find Number of Factors of a Number | Sum of Factors of a Number

Average of numbers formula | Average of a series of numbers

Simple Average Formulas for Aptitude Questions and Answers