Why Learn Complements? Complement arithmetic is the foundation of how processors perform subtraction and handle negative numbers. Instead of building separate subtraction circuits, hardware designers use complements to convert subtraction into addition—saving chip area and power. Understanding this is essential for digital design and computer architecture.
8 min read | Beginner Level
What You'll Learn
- Understand one's complement and two's complement representations
- Calculate complements of binary numbers quickly
- Learn why two's complement is preferred in modern hardware
- Apply complement arithmetic to subtraction operations
What Are Complements?
In binary arithmetic, there are two types of complements used to represent and manipulate signed numbers:
- One's complement: Flip all bits (0 → 1, 1 → 0)
- Two's complement: One's complement + 1
Complements allow hardware to perform subtraction using addition circuits, eliminating the need for separate subtraction logic.
One's Complement
To find the one's complement of a binary number, simply invert every bit:
Binary number : 11001101
One's complement : 00110010
^^^^^^^^ (all bits flipped)
Rule: Every 0 becomes 1, and every 1 becomes 0.
How One's Complement Works
One's complement is the simplest form of complement arithmetic. It's calculated by inverting all bits in a binary number.
Examples:
| Original Binary | One's Complement | Decimal (Original) | Decimal (Complement) |
|---|---|---|---|
| 00001010 | 11110101 | +10 | -10 (in one's complement) |
| 01111111 | 10000000 | +127 | -127 |
| 10101100 | 01010011 | -83 (in one's complement) | +83 |
Using One's Complement for Subtraction
To subtract binary number B from A using one's complement:
- Find the one's complement of B (invert all bits)
- Add A and the one's complement of B
- If there's a carry-out, add it back to the result (end-around carry)
Example: Subtract 5 from 9 (both 4-bit):
A = 9 (decimal) = 1001 (binary)
B = 5 (decimal) = 0101 (binary)
Step 1: One's complement of B:
0101 → 1010
Step 2: Add A + one's complement of B:
1001
+ 1010
------
10011 (carry-out = 1)
Step 3: Add carry-out to result:
0011
+ 1
------
0100 = 4 (correct answer: 9 - 5 = 4)
The end-around carry is a unique feature of one's complement arithmetic. This extra step is why one's complement is less efficient than two's complement in hardware.
Drawbacks of One's Complement
One's complement has several disadvantages that led to its obsolescence:
- Two representations of zero: +0 (00000000) and -0 (11111111)
- End-around carry: Requires an extra addition step, slowing down operations
- More complex circuits: The end-around carry adds hardware complexity
Having two zeros (+0 and -0) complicates comparison operations and wastes one bit pattern. This is why modern systems universally use two's complement instead.
Historical Context One's complement was used in some early computers like the UNIVAC 1100 series and CDC 6000 series. However, by the 1970s, virtually all new computer designs switched to two's complement due to its simpler hardware implementation and single zero representation.
Two's Complement
Two's complement is the standard method for representing signed integers in modern digital systems. It solves the problems of one's complement by using a different calculation method.
How to Calculate Two's Complement
To find the two's complement of a binary number:
- Find the one's complement (invert all bits)
- Add 1 to the result
Example: Find the two's complement of 11001101:
Binary number : 11001101 One's complement : 00110010 (invert all bits) Add 1: + 1 ------------------------------ Two's complement : 00110011 ------------------------------
More Examples of Two's Complement
| Decimal | Positive Binary | Negative (Two's Complement) |
|---|---|---|
| +5 | 00000101 | 11111011 (-5) |
| +10 | 00001010 | 11110110 (-10) |
| +127 | 01111111 | 10000001 (-127) |
| +1 | 00000001 | 11111111 (-1) |
Quick two's complement check: Add a number and its two's complement. The result should always be zero (with carry-out discarded). Example: 00000101 + 11111011 = 100000000 → 00000000.
Why Two's Complement is Preferred
Two's complement has become the universal standard for signed arithmetic in digital hardware because of these advantages:
| Feature | One's Complement | Two's Complement |
|---|---|---|
| Zero Representation | Two (+0 and -0) | One (00000000) |
| Subtraction Method | End-around carry needed | Simple addition (ignore carry) |
| Hardware Complexity | More complex | Simpler |
| Range (8-bit) | -127 to +127 | -128 to +127 |
| Sign Extension | Complex | Simple (copy MSB) |
Where is Two's Complement Used? All modern processors (x86, ARM, RISC-V, MIPS) use two's complement for signed integers. This includes CPUs in smartphones, laptops, servers, embedded systems, and microcontrollers. The ALU (Arithmetic Logic Unit) performs both addition and subtraction using the same adder circuit by taking the two's complement of the subtrahend.
Using Two's Complement for Subtraction
To compute A - B using two's complement:
- Find the two's complement of B
- Add A and two's complement of B
- Discard any carry-out from the MSB
Example: Calculate 12 - 7 using 8-bit two's complement:
A = 12 (decimal) = 00001100 (binary)
B = 7 (decimal) = 00000111 (binary)
Step 1: Two's complement of B:
00000111 → 11111000 (invert) + 1 = 11111001
Step 2: Add A + two's complement of B:
00001100
+ 11111001
----------
100000101 (carry-out = 1, discard it)
Result: 00000101 = 5 (correct: 12 - 7 = 5)
Unlike one's complement, there's no end-around carry in two's complement. The carry-out is simply ignored, making the hardware simpler and faster.
Quick Check Q: What is the two's complement of binary 01010101?
Show Answer
A: 10101011
Step-by-step:
Original: 01010101
One's complement: 10101010 (invert all bits)
Add 1: + 1
------------
Two's complement: 10101011
Decimal interpretation: 01010101 = +85, so 10101011 = -85 in two's complement.
Complement Properties
Important Properties to Remember
- Double complement returns original: Complement of complement = original number
- Two's complement of two's complement of 5 = 5
- Complement represents negation: In two's complement, the complement of a number is its negative
- 5 + (-5) = 00000101 + 11111011 = 00000000
- Range asymmetry: Two's complement has one more negative value than positive
- 8-bit range: -128 to +127 (not -127 to +127)
- Most negative value (10000000) has no positive equivalent
- Sign extension: To extend an n-bit two's complement to m bits, copy the MSB
- 4-bit 1101 (-3) → 8-bit 11111101 (-3)
- 4-bit 0101 (+5) → 8-bit 00000101 (+5)
Common Beginner Mistakes
Mistake #1: Forgetting to add 1 in two's complement
Wrong: Thinking two's complement is just inverting bits
Right: Two's complement = invert bits AND add 1
Why? One's complement just inverts. Two's complement needs the extra +1 to eliminate the dual-zero problem.
Mistake #2: Adding end-around carry in two's complement
Wrong: After adding in two's complement, adding the carry-out back to the result
Right: In two's complement, discard (ignore) the carry-out from the MSB
Why? End-around carry is only used in one's complement, not two's complement.
Mistake #3: Confusing complement with inverse
Wrong: Thinking the complement changes the value of the number
Right: The complement is a different representation method, specifically for representing negative numbers
Why? Complements are a way to represent negative values in binary, not a mathematical operation on the value itself.
Mistake #4: Incorrect sign extension
Wrong: Extending 4-bit 1101 to 8-bit as 00001101
Right: Extend by copying MSB: 11111101
Why? The MSB is the sign bit. Extending with 0s would change a negative number to positive.
Summary
In this tutorial, you learned:
- One's complement is found by inverting all bits (0 → 1, 1 → 0)
- Two's complement is one's complement plus 1
- One's complement has two zeros (+0 and -0) and requires end-around carry
- Two's complement has one zero and simpler subtraction (no end-around carry)
- All modern processors use two's complement for signed arithmetic
- Subtraction is performed by adding the two's complement (A - B = A + two's complement of B)
- Two's complement allows the same hardware adder to perform both addition and subtraction