2's Complement:
2's complement is a method used in computer systems to
represent negative numbers in binary. It simplifies arithmetic operations
(like addition/subtraction) by allowing the same hardware to handle both
positive and negative numbers.
1. Purpose:
o Represents negative numbers in binary.
o Eliminates the need for separate subtraction circuits (uses addition only).
2. How It Works:
o Step 1: Invert all bits (1→0, 0→1) → This is the 1's complement.
o Step 2: Add 1 to the 1's complement → Final 2's complement.
3. Example (4-bit system):
o Represent -5 in 2's complement:
Binary of +5: 0101
1's complement: 1010 (flipped bits)
2's complement: 1010 + 1 = **1011** (this is -5)
Why Use 2's Complement?
No "negative zero": Only one representation for zero (0000).
Simplifies arithmetic:
o 5 + (-3) = 2 → 0101 + 1101 = **0010** (ignoring overflow).
Widely used: Standard in modern computers.
Range of Numbers (n-bit system)
Positive: 0 to 2^(n-1) - 1
(e.g., 4-bit: 0 to 7).
Negative: -1 to -2^(n-1)
(e.g., 4-bit: -1 to -8).
Quick Practice
Convert -7 to 2's complement (4-bit):
1. +7 = 0111
2. 1's complement = 1000
3. 2's complement = 1001 (final answer).
Summary
2's complement = 1's complement + 1.
Used for efficient binary arithmetic in computers.
Eliminates redundancy (e.g., no -0 issue).
Need a real-world analogy? Think of it like a car odometer rolling over
from 0000 to 9999 to represent negative values!
2's Complement Practice Problems (with Answers)
Problem 1: Convert to 2's Complement (4-bit system)
1. -3
o Step 1: Binary of +3 = 0011
o Step 2: 1's complement = 1100
o Step 3: Add 1 → 1101
o Answer: 1101
2. -6
o +6 = 0110 → 1's complement = 1001 → Add 1 = 1010
o Answer: 1010
Problem 2: Find the Decimal Value of 2's Complement
1. 1101
o Step 1: Invert → 0010
o Step 2: Add 1 → 0011 (decimal 3)
o Sign: MSB is 1 → negative
o Answer: -3
2. 1001
o Invert → 0110 → Add 1 → 0111 (7)
o Answer: -7
Problem 3: Arithmetic Using 2's Complement
1. Calculate 4 + (-2) (4-bit)
o 4 = 0100, -2 = 1110 (since +2 = 0010 → 1's = 1101 → 2's = 1110)
o Add: 0100 + 1110 = **0010** (decimal 2)
o Answer: 0010 (2)
2. Calculate -5 + 3 (4-bit)
o -5 = 1011, 3 = 0011
o Add: 1011 + 0011 = **1110**
o Convert 1110 to decimal: Invert → 0001 → Add 1 → 0010 (2) → MSB=1 → -2
o Answer: 1110 (-2)
Problem 4: Overflow Detection
1. Add 7 + 1 (4-bit)
o 7 = 0111, 1 = 0001
o Result: 0111 + 0001 = **1000** (decimal -8 due to overflow!)
o Key Point: Overflow occurs if the sign bit flips incorrectly.
Bonus: 8-bit 2's Complement
1. Convert -25 to 8-bit 2's complement
o +25 = 00011001
o 1's complement = 11100110
o Add 1 → 11100111
o Answer: 11100111
Answers Summary
Problem Answer
1. (-3) 1101
2. (-6) 1010
3. (1101 → ?) -3
4. (1001 → ?) -7
5. (4 + (-2)) 0010 (2)
6. (-5 + 3) 1110 (-2)
7. (7 + 1) Overflow!