Two’s complement is used widely in binary related problems deals with zero and one only. In this article, we will discuss two’s complement along with arithmetic operations on two’s complement.

What is Two’s Complement?

Two’s complement is a mathematical operation on binary numbers and is an instance of radix complement (10’s complement). It is utilized in computing. Two’s complement is a technique of setting integers in order thatnot unusual place math issues come to be easy to implement. Two’s complement is a method that encodes nice and poor numbers in a binary variety representation. In the case of nice numbers, zero is with inside themaximumsizeablerolewhilst in the case of poor 1 is with inside themaximumsizeablerole. To get two’s complement of binary variety, first convert all of thezeros to one and all of the 1’s into zero in different phrases transpose that binary variety or invert that binary variety. After inverting the binary varietyupload 1 to LSB (at Least a significant bit). Two’s complement can be calculated for decimals and binary numbers.

Binary to two’s complement:

To get two’s complement of a binary number, first convert all the zeros to one and all the ones into zero. In other words, transpose that binary number or invert that binary number. After inverting the binary number add 1 to LSB (Least significant bit).

Example 1

Convert 00110010 into two’s complement?

Solution

Step 1:First invert the binary number

00110010 change into 11001101 after inverting

Step 2:Now add 1 in the LSB.

The two’s complement of 00110010 is 11001110.

Example 2

Convert 011100 into two’s complement?

Solution

Step 1:First invert the binary number.

011100 change into 100011 after inverting.

Step 2:Now add 1 in the LSB.

100011 + 1 = 100100

The two’s complement of 011100 is 100100.

Two’s Complement Calculator is a useful online calculator that can assist in finding two’s complement at one click.

Decimal to two’s complement:

The best way to discover two’s complement conversion is to start with small numbers of bits e.g., let’s start with 4-bits which can represent 16 decimal numbers range -8 to 7. 8-bit has a range of -128 to 127.

Positive integer

Example 1

Convert 9 to Two’s complement

Solution

Step 1:First of all, convert the decimal number into a binary number.

(9)2 = (1001)2

Step 2:Now invert the binary number.

1001 becomes 0110

Step 3:Now add 1 to LSB

                             0110 + 1 = 0111

The two’s complement of 9 is 0111

Example 2

Convert 36 to Two’s complement.

Solution

Step 1:First of all, convert the decimal number into a binary number.

(36)2 = (100100)2

Step 2:Now invert the binary number.

100100 becomes 011011

Step 3:Now add 1 to LSB.

                             011011 + 1 = 011100

The two’s complement of 36 is 011100.

Negative integer:

The negative number is formed by taking the positive number complementing it (bit-by-bit inversion) and adding 1 to the results

Example

Convert -7 to Two’s complement

Solution

Step 1:First of all, convert the positive number 7 into a binary number.

We have

(7)2 = (0111)2

Step 2:Now invert the binary number

0111 becomes 1000

Step 3:Now add 1 to LSB

                             1000 + 1 = 1001

We have the two’s complement of 7 is 1001

Step 4:Now invert the number.

1001 becomes 0110

Step 5:Now add 1 to LSB

0110 + 1 = 0111

Hence the two’s complement of -7 is 0111

Arithmetic Operations on Two’s complement

 We can add, subtract, multiply or divide two or more Two’s complements. Let us discuss them.

Addition of Two’s Complement

The addition of Two’s complement is just like binary addition. As 1 + 1 equals to zero and carrying one to the other term. 0 + 0 makes zero result. 1 + 0 or 0 + 1 gives 1 as an output. Let us take some examples in order to understand this concept.

Example 1

Add the Two’s complement of the following numbers

11001100, 11100011

Solution

Step 1:Place the addition sign between the numbers.

11001100 + 11100011

Step 2:Solve the addition.

   11001100

+ 11100011

  110101111    

You can also use an online Two’s Complement Addition Calculator to solve such problems.  

Example 2

Add the Two’s complement of the following numbers

11001111, 11101111

Solution

Step 1:Place the addition sign between the numbers.

11001111 + 11101111

Step 2:Solve the addition.

  11001111

+ 11101111

 110111110

Subtraction of Two’s Complement

Subtraction of Two’s complement is just like binary subtraction. As 1 – 1 equals to zero. 0 – 0 makes zero results. 1 – 0 gives 1 as an output. 0 – 1 can be done by taking a carry from other digits the carry will be 2. Let us take some examples in order to understand this concept.

Example 1

Subtract the Two’s complement of the following numbers.

11001100, 10100011

Solution

Step 1:Place the subtraction sign between the numbers.

11001100 – 10100011

Step 2:Solve the subtraction.

   11001100

– 10100011

   00101001

Example 2

Subtract the Two’s complement of the following numbers

11001111, 10101111

Solution

Step 1:Place the subtraction sign between the numbers.

11001111 – 10101111

Step 2:Solve the subtraction.

  11001111

– 10101111

  00100000

Multiplication of Two’s Complement

Multiplication of Two’s complement is just like binary multiplication. Let us take some examples in order to understand this concept.

Example 1

Multiply the Two’s complement of the following numbers

11001, 1010

Solution

Step 1:Place the subtraction sign between the numbers.

11001 x 1010

Step 2:Solve the Multiplication.

  11001

x 1010

 00000

11001x

00000xx

11001xxx

  11111010

Example 2

Multiply the Two’s complement of the following numbers

100011, 1011

Solution

Step 1:Place the subtraction sign between the numbers.

100011 x 1011

Step 2:Solve the Multiplication.

100011

x 1011

100011

 100011x

    000000xx

100011xxx

  110000001

Summary

Two’s complement is used for addition and subtraction to be done easily without any logic. Binary and decimals can be converted into two’s complements. Arithmetic operations can be done on two’s complement. This article is very simple. Once you learn the basics of this article you will be master it.

Post Your Thoughts