2′s Complement

💡
Key learnings:
  • 2’s Complement Definition: 2’s complement is a binary number system technique used to represent positive and negative numbers, allowing easier binary subtraction.
  • Calculation Methods: Methods to find 2’s complement include subtracting each bit from 1 and adding one to the result, providing consistent results across methods.
  • Subtraction Technique: Using 2’s complement for subtraction involves converting the subtrahend to 2’s complement and adding it to the minuend, simplifying binary arithmetic.
  • Negative Representation: In binary systems, negative numbers are represented using 2’s complement, where the sign bit ‘1’ indicates a negative value.
  • 2’s Complement Examples: Demonstrates practical application of 2’s complement in various binary operations, ensuring clarity on its uses and benefits.

Complement Number System

2’s complement is the usual signed-binary encoding. For a number whose base is N, the (N-1)’s complement is the difference from the highest same-width digit string, and adding one gives the N’s complement. In decimal (base 10) that (N-1)’s form is 9’s complement. In binary, 2’s complement is the 1’s complement plus one.
Method 1: Subtract the number from the highest same-width value. Subtracting 25 from 99 in decimal gives 74, the 9’s complement.

Method 2: Subtract each digit from 9, the highest decimal digit. 9 – 2 and 9 – 5 again give 74. Both methods match, so either may be used.

Binary Number System: A Binary number uses only 0s and 1s and has base 2. Subtracting each binary digit from 1 yields the 1’s complement. Adding 1 to that result gives the 2’s complement. The short way to form the 1’s complement is to invert each digit: replace 0s with 1s and 1s with 0s.

The same two methods apply in binary, plus a bit-flip shortcut, to find 1’s and 2’s complement. Example: 2’s complement of 0100. A leading zero makes this a four-bit word, a common power-of-two width.
Method – 1 Subtract it from 1111, the highest four-bit value, to find the 1’s complement. 1111 – 0100 is 1011. 2’s complement is 1011 + 1, which is 1100.

Method – 2 Subtract every individual digit from 1 to get the 1’s complement. For 0100 that is 1 – 0, 1 – 1, 1 – 0, 1 – 0, which is 1011.
2’s complement will be 1011 + 1 = 1100.

Method – 3 Replace each 1 by 0 and each 0 by 1 to find the 1’s complement. Adding one to that result gives the 2’s complement.

For 0100, replacing 1 by 0 and 0 by 1 gives 1011. Adding 1 gives (1011 + 1), which is 1100.
All three methods give the same 4-bit result, so any one of them may be used.
2′s Complement examples

2’s complement representation of a positive number and its negative.

 

Why We Do Need 2’s Complement?

The main use of 2’s complement is subtraction of two binary values with the same adder. A computer stores only binary, and the binary number system has no minus sign, so a sign bit is used. If the sign bit is 1 the value is negative. If it is 0 the value is positive.

For subtraction of binary numbers, use the following steps.

Subtracting a Smaller Number from a Larger Number

  1. Find 2’s complement of the smaller number.
  2. Add the larger and 2’s complement of the smaller number.
  3. Discard the carry.
  4. After discarding the carry, keep the remaining bits. That value is the positive difference.
2's complement subtraction

Subtracting Larger Number from Smaller Number

  1. Find 2’s complement of larger number.
  2. Add 2’s complement of larger number to the smaller number.
  3. If no carry is generated, find the 2’s complement of the result and the result will be negative.
  4. If a carry is generated here, the assumed larger/smaller order or the chosen bit width is wrong. Do not treat that carry-discarded sum as a negative result.

binary subtraction
Subtraction of larger number from smaller number.

Advantages of 2’s Complement

  1. Subtraction can be done with the help of 2’s complement method.
  2. The same adder circuit can add or subtract.
  3. End around carry need not be performed as in the case of 1’s complement.
  4. Negative number can be represented using 2’s complement.
Want To Learn Faster? 🎓
Get electrical articles delivered to your inbox every week.
No credit card required—it’s 100% free.

About Electrical4U

Electrical4U is dedicated to the teaching and sharing of all things related to electrical and electronics engineering.

Leave a Comment