Two's Complement

Two's complement is a method used to represent negative numbers in binary and to perform binary subtraction efficiently.

Key Concept

When adding two binary numbers, an extra carry bit may appear, which is discarded:
1001+0111=10000


How to Calculate Two's Complement

To compute the two's complement of a binary number:

  1. Take the 1's complement (invert all bits).
  2. Add 1 to the result.

Example:
Find two's complement of 1011 (4-bit representation):
1’s complement: 10110100
Add 1: 0100+0001=0101


Signed Numbers

Signed numbers use the most significant bit (MSB) as a sign bit:

Examples:


Finding Negative of a Number

To find the negative representation of a binary number:

  1. Take its binary form.
  2. Apply two's complement.

Example: Represent 6 in 4-bit:
+6=0110
Two's complement:
01101001+1=1010
So, 6=1010.


Binary Subtraction Using Two's Complement

Instead of direct subtraction, add the two's complement of the subtrahend to the minuend.

Example:
01110101
Step 1: Two's complement of 0101:
01011010+1=1011
Step 2: Add to minuend:
0111+1011=0010 (discard carry)
Result: 0010=2.