Two’s Complement: Definition, Conversion,& Examples

How do you convert binary and decimal numbers to two’s complement

The concept of two’s complement has been established since the middle of the 19th century, but it was not until the late 1940s that it became widely accepted. when John Tukey suggested using it as a different magnitude to express negative integers in binary. Its popularity was fueled by its efficiency, speed, and capacity to operate on signed integers in arithmetic.

The term two’s complement is employed in the computer system to perform significant arithmetic operations on the positive and negative integers. The two digits 1 & 0 are the binary numbers and the computer can apprehend these binary numbers.

So how are we expected to use computers to conduct computations with negative numbers? We employ complements of one and two. In this article, we will address an interesting concept of the two’s complement. We will elaborate on its definition, important conversions, and examples.

Definition:

“The two’s complement represents negative numbers by flipping all of the bits in a number and adding 1.” However, positive numbers do not require a unique representation because they may be represented in binary form. It is mostly used for negative numbers to convert into binary number systems easily.

MostSignificant Bit:

The most significant bit is the leftmost bit in a binary number. It aids in representing the signed numbers in the two’s complement. Consider the case when we have the number 01001, where 1 is the most important digit since it is the leftmost bit.

  • If the most significant number is 1, it implies that it is a negative one.
  • If the most significant number is 0, it represents that it is positive.

Conversions:

For the conversion of numbers into two complements, we follow the steps,

Decimal numbers:

For the conversion of decimal numbers into two’s complements follow the below steps,

  1. Convert the number into binary form (0,1)
  2. Convert all the o’s into 1 and 1’s into 0 you get the one’s complement form
  3. Add 1 into the output (result) of step no. 2.

Binary numbers:

In this section, we convert the binary numbers into two complements for this purpose follow the below steps

  1. Start by representing the binary numbers
  2. Convert all the o’s into 1 and 1’s into 0 you get the one’s complement form
  3. Add 1 to the output(result) of step no. 2.

How do you convert binary and decimal numbers to two’s complement?

In this section, we are going to understand how to convert binary to two’s complement as well as decimal numbers to 2’s complement through examples.

Example1:

Convert the number into two complements 9

Solution:

for the solution must follow the above steps

Step1: Convert the number into binary form

29
24         1
22          0
 1          0

So, (1001)2 is the binary form of the number.

The range of 9 is between -128 to 127 so it lies in 8 bits and then converts into 8 bits

(0000 1001) After completing 8 bits

Step 2: Covert all the 0’s into 1’s and vice versa and we get the one’s complement form

= 1111 0110

Step 3: Add 1 to the one’s complement

1 1 1 1 0 1 1 0

+                    1

———————–

 1 1 1 1 0 1 1 1                     

Example 2:

Covert the given decimal 518 into 2s complement

Solution:

The solution must follow the above steps,

Step 1:

Convert the given number into binary form

2518
2259 – 0
2129 – 1
264 – 1
232 – 0
216 – 0
28 – 0
24 – 0
22 – 0
1 – 0

The binary form of the given number after completing 12 bits is (0010 0000 0110)

Step 2: Convert all the o’s into 1 and 1’s into 0 you get the one’s complement form,

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

Step 3: Add one to the result of step 2,

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

+                                1

—————————–

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

The two’s complement of 518 is (1 1 0 1 1 1 1 1 1 0 0 0)

Example 3: (for binary numbers)

Convert the given binary number (1100010)into two’s complement

Solution:

For the solution follow the following steps for binary numbers:

Step 1: In binary form the number is

(1100010) After completing 8 bits

 = (0110 0010)

Step 2: Convert all the o’s into 1 and 1’s into 0 you get the one’s complement form,

(1 0 0 1 1 1 0 1)

Step 3: Adding“1” to the result (output) of step no. 2.

(1 0 0 1 1 1 0 1)

+                   1

————————

1 0 0 1 1 1 0 0

So, the two’s complement of the given binary number is (1 0 0 1 1 1 0 0)

Example 4:

Convert the given binary number(1000011) into two’s complement

Solution:

For the solution follow the following steps for binary numbers:

Step 1: The number in binary form:

So the number is (1000011)

After completing bits = (0 1000011)

Step 2: Convert all the o’s into 1 and 1’s into 0 you get the one’s complement form,

 After converting = (1 0 1 1 1 1 0 0)

Step 3: Add 1 to the result of step no. 2.

(1 0 1 1 1 1 0 0)

+                     1

——————–

1011 1101

So, the two’s complement of a given binary number is (1011 1101).

Wrap Up

In this article, we have explored an important the two’s complement. We have elaborated on a brief overview of the history of this fundamental concept. We have discussed its definition and significant conversions. We have discussed the MSB (most significant bit) used to indicate whether the number is positive or negative.

You might also like our TUTEZONE section which contains exclusive tutorials on how you can make your life simpler using technology.

Recommended For You

About the Author: Ranjit Ranjan

More than 15 years of experience in web development projects in countries such as US, UK and India. Blogger by passion and SEO expert by profession.

Leave a Reply