Two’s (2’s) complement: An Introduction With Examples 

CodingHero - Two’s (2’s) complement: An Introduction With Examples  aopu2nVhra3fcUhBWw iCmu9YGCjyFQXtEL85LiOHxFwD8bew6x4ez21JsbFsJpTCVwWFgELEMAoSHCfhRsEBoIc86BefTFKW9smp1KoojvLIcrbs5tSEWDZSpAArlss5bGOOj6OdEdid Pwuv sHcYiUfwCDvFcI4V2IxSD5NrScfn oPWm mQn7lCQUM ylsBazg

One of the most common methods of number representation used in digital systems is the binary number system. There are just two variables or digit values available in the binary system: 0 (off) and 1 (on). represented by any object with only two conceivable operational states.

There are typically two different sorts of compliments for binary numbers: the complement of 1 and the complement of 2. Simply inverting the provided integer to obtain a binary number refers to the complement of 1. 

For example, 001101 is the one’s complement of binary number 110010. While adding 1 in the least significant bit of the 1’s complement, it refers to the two’s complement. For example, (01101) + 1 = 01110 is the two’s complement of binary integer 10010.

What is a two’s (2’s) complement?

The 2’s complement of a binary integer may be created using a straightforward technique. Simply invert the provided number and add 1 to the least significant bit (LSB) of the output to obtain a binary integer’s 2’s complement.

Examples of two’s (2’s) complement

We have explained the concept of 2s complement with the help of some examples.

Example 1:

Find the 2s complement if the decimal value is 17 and the number of bits is 16.

Solution:

Number in decimal = 17

Step 1: First, convert 17 to binary:

217
28 – 1 
24 – 0 
22 – 0 
1 – 0

Binary of 17 = 10001

Selected Bits = 16

Binary Number after completing bits = 0000 0000 0001 0001

Step 2: Taking One’s complement of the binary number:

Write down the binary Number

0000000000010001

Invert all values (Swap each 0 with 1 and each 1 with 0):

0000000000010001
1111111111101110

Step 3: Taking Two’s complement by adding 1 in the previous binary number:

1111111111101110
+1
1111111111101111

Number in 2’s complement with 16-bit representation

Decimal 17
Binary0000 0000 0001 0001
2’s Complement1111 1111 1110 1111

The above example can also be solved by using a  two’s complement calculator to perform the conversions within seconds. The calculation explains the step-by-step solutions to the problems.

CodingHero - Two’s (2’s) complement: An Introduction With Examples  FfLnZHIL2odF4gN1CLFXwNotmS9OJz5NojQdWxJB4OGWz5Br5h7hJAWLoancLtvhHhaWwrOVkOO6K Lxiclzv ezzxb fuaqOAZXk97GRm2iyPbHlhcRI5wiTVLvOJMNdJcXi3bYiLv2WuL0r6kNvnqMjJeN04G7yNcFSWiXE9Md2ymbAnkEX NJAK6KSQzYV W6Ug

To calculate the answer, we have to follow the steps:

  • First, select the type of input data with respect to the base.
  • Enter the number of bits.
  • Enter the value
  • Press the calculate button.

Example 2:

Find the 2s complement if the decimal value is 172 and the number of bits is 20.

Solution:

Number in decimal = 172

Step 1: First, convert 172 to binary:

2172
286 – 0 
243 – 0 
221 – 1 
210 – 1 
25 – 0 
22 – 1 
1 – 0

Binary of 172 = 10101100

Selected Bits = 20

Binary Number after completing bits = 0000 0000 0000 1010 1100  

Step 1:

Taking One’s complement of the binary number:

Write down the binary Number

00000000000010101100

Invert all values (Swap each 0 with 1 and each 1 with 0):

00000000000010101100
11111111111101010011

Step 2:

Taking Two’s complement by adding 1 in the previous binary number:

11111111111101010011
+1
11111111111101010100

Number in 2’s complement with 16-bit representation

Decimal 17
Binary10101100
2’s Complement1111 1111 1111 0101 0100

Uses for Binary 2’s Complement Numbers

The 2’s complement of a binary integer is used for a variety of purposes, primarily in signed binary number encoding and different arithmetic operations for binary numbers, such as additions and subtractions. It is highly helpful in computer number representation since the 2’s complement form is unambiguous.

Summary:

In the above article, we have learned the basic definition, method, and examples of two’s (2’s) complement. Now you will solve any problems of two’s (2’s) complement relative very easily and it enhances your interest in two’s (2’s) complement.

Leave a Comment