Two's Complement Arithmetic
What you'll learn: How to perform addition and subtraction using two's complement, the standard method computers use for signed integers.
Why Two's Complement?
You've learned that two's complement represents negative numbers by flipping all bits and adding one. But why is this the standard approach? The brilliant reason: it makes addition and subtraction work the same way for both positive and negative numbers.
With two's complement, your computer doesn't need separate circuits for adding and subtracting—one adder handles everything. This simplifies hardware design dramatically.
Adding with Two's Complement
When adding signed integers in two's complement:
- Add the binary numbers normally (just like unsigned addition)
- Ignore any carry-out from the leftmost bit
- The result is automatically correct!
Example (using 4-bit numbers):
- 3 + (-2) = 1
- 3 in binary:
0011 - -2 in two's complement:
1110 - Add them:
0011 + 1110 = 10001 - Ignore the leftmost carry →
0001= 1 ✓
Subtracting with Two's Complement
Subtraction is even easier: negate the second number and add.
To compute A - B:
- Find the two's complement of B (flip bits, add 1)
- Add A + (-B) using normal addition
Example: 5 - 3 = 2
- Convert 3 to -3:
0011→1100+0001=1101 - Add:
0101 + 1101 = 10010 - Ignore carry →
0010= 2 ✓
Overflow Detection
Overflow occurs when the result is too large for your bit width. Watch for: both operands positive but result negative, or both negative but result positive.
Key Takeaway: Two's complement lets computers use one simple addition circuit for all signed arithmetic—just add the bits and ignore the final carry, making it the universal standard for representing negative numbers in hardware.