गणित / Math

What is Two’s Complement, Its Importance, and how to find it?

What is Two’s Complement, Its Importance, and how to find it?

Two’s Complement is the most useful method in the binary number system to represent the no’s in the digital system. It is mostly used to represent signed integers on the computer in the form of fixed binary values in the field of computer science. It is a simple technique used to construct the binary integer.

In mechanical calculators and decimal addition machines, the complements approach is utilized to calculate subtraction in decimals. In 1945, John von first introduced Two’s Complement binary encoding in his First Draft of a Report on the EDVAC project.

Moreover, in 1949 EDSAC by influencing this draft introduced the negative binary number by use of Two’s complement. By this assertion, we encoded the negative numbers in a computer.

In this article, we will discuss the definition, importance, and detailed discussion of how to find an integer by two’s complement and understand it with the help of examples.

Definition of Two’s Complement

Two’s Complement is executed by inverted of given number (in a binary system) and adding a place value of 1 to the least significant bit (LSB) in inverted number.”

Importance:

The other techniques do not encode negative integers. But with the help of 2’s complement technique, we encode a negative integer. Moreover, Positive numbers don’t require special representation because they may be expressed as regular binary numbers. Most computers store signed numbers using Two’s Complement.

The 2’s Complement of a binary integer is used for different arithmetic operations of binary numbers, such as additions and subtractions. It is highly helpful in computer number representation.

Finding 2’s Complement through Binary Number:

In this section, we discussed the methods to find the binary number with the help of 2’s Complement. Generally, it is applied to integers (Positives & Negatives). The process of finding for positive number is simple while for a negative number, we apply an exclusive technique.

For positive integers:

Positive integers are simply converted into the binary system. The finding steps are discussed below.

  1. Firstly, we covert the given integer into the binary number (defined on 0 & 1)
  2. Binary numbers covert into the bit system.
  3. Swap the binary number (0 in 1 & 1 in 0).
  4. Finally, added 1 in the inverted binary number to get a result.

For negative integers:

To find the binary number for a negative integer first convert the number into a positive form. Detailed steps are discussed below.

  1. Firstly, make the no positive.
  2. Find the binary number.
  3. Convert the binary number into a bit system.
  4. Swap the binary number (0 in 1 & 1 in 0).
  5. Finally, added 1 in the flipping binary number.

A two’s complement calculator by Allmath (https://www.allmath.com/twos-complement.php) is a helpful resource to evaluate the two’s complement for positive and negative integers in no time with steps.                          

Subtractions By 2’s Complement:

Subtraction of two binary numbers used 2’s Complement method followed as below steps.

  1. Firstly, take 2’s Complement of that term that is subtracted.
  2. Add that inverted no in the first term.
  3. If the above result carries bit 1 then dropped it and it gives a positive answer.
  4. if it carries not bit 1 then take 2’s Complement of the above result and it will be a negative number.

Example:

In this section, we learn in detail 2’s Complement method with the help of examples.

Example 1:

Find 2’s Complement of 10001010.

Solution:

Step 1: swap the no. (1 in 0 & 0 in 1)

Inverted number = 01110101

Step 2: Add 1 in the least significant bit (LSB).

2’s Complement = 01110101 + 1

2’s Complement = 01110110

Example 2:

Find 2’s Complement of 1001.01100.

Solution:

Step 1: Swap the no. (1 in 0 & 0 in 1)

Inverted number = 0110.10011

Step 2: Add 1 in the least significant bit (LSB).

2’s Complement = 0110.10011 + 1

2’s Complement = 0110.10100

Note: we note that in examples 1 & 2 the number is already given in the form of the binary system, so we do not transform the number in the binary system (skip the step-1 and start from step-2 discussed in positive integer)

Example 3:

Find the solution of 10101 – 00111.

Solution:

Step 1: take the 2’s Complement of 00111.

Inverted number = 11000

2’s Complement = 11000 + 1 = 11001

Step 2: Add the term 10101.

 Addition = 10101 + 11001 = 101110

This number carries no bit.

Step 3: Take 2’s Complement of this result.

  1. First, inverted the number by swapping (1 in 0 & 0 in 1)

Inverted number = 010001

  1. 2’s Complement = 010001 + 1 = 010010

This is the negative number.

           Solution of 10101 – 00111 = 010010.

 

Example 3:

Find the 2’s Complement of 15 and the number of bits is 9.

Solution:

Step 1: Firstly, convert the 15 from decimal to binary.

2

15

2

7 – 1

2

3 – 1

 

1 – 0

   
   

Binary number of 15 = (1011)2

Step 2: Complete the given bits.

After completed bits = 000001011

Step 3: swap the number (0 in 1 & 1 in 0).

Inverted number = 111110100

Step 4: Add 1 in an inverted number for 2’s complement.

2’s Complement = 111110100 + 1 = 111110101

2’s Complement of 15 = 111110101

Summary:

In this article, we discussed the detailed explanation of the Two’s Complement. Moreover, discussed its definition, its solving techniques for positive and negative integers, and subtraction by 2’s Complement. Discussed its different examples for a better understanding of 2’s Complement.

By reading this article, we hope you can solve its related problems easily.

Disclaimer: sarkariguider.com is created only for the purpose of education and knowledge. sarkariguider.com does not own these book/materials, neither created nor scanned. We provide the links which is already available on the internet. For any quarries, Disclaimer are requested to kindly contact us, we assured you we will do our best. We do not support piracy, this copy was provided for students who are financially troubled but deserving to learn. If in any way it violates the law or there is a problem, please mail us- sarkariguider@gmail.com

About the author

Kumud Singh

M.A., B.Ed.

Leave a Comment

(adsbygoogle = window.adsbygoogle || []).push({});
close button
(adsbygoogle = window.adsbygoogle || []).push({});
(adsbygoogle = window.adsbygoogle || []).push({});
error: Content is protected !!