Binary subtraction
Subtract these binary numbers: 0 - 0
The answer will be in signed binary (two's complement).
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| - | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Binary subtraction can be performed using two's complement addition:
- Convert the number being subtracted to two's complement (flip bits and add 1)
- Add the two numbers together using binary addition
- The result is in two's complement form
Example: Calculate 01010000 - 00001100
Step 1: Convert 00001100 to two's complement
Flip: 11110011
Add 1: 11110100
Step 2: Add 01010000 + 11110100 = 01000100
Result: 01000100 (68 in denary)Binary subtraction is typically performed using two's complement addition, which is how computers actually perform subtraction.
Method: Two's Complement Addition
To calculate A - B:
- Keep A as it is
- Convert B to its two's complement:
- Flip all the bits in B (0 becomes 1, 1 becomes 0)
- Add 1 to the result
- Add A and the two's complement of B using binary addition
- Ignore any carry bit that extends beyond 8 bits
- The result is in two's complement form
Example: 80 - 12
A = 80 = 01010000
B = 12 = 00001100
Step 1: Convert B to two's complement
Flip bits: 11110011
Add 1: 11110100
Step 2: Add A + (-B)
01010000
+ 11110100
-----------
101000100 (ignore the leftmost 1 as it's the 9th bit)
01000100 = 68 in denary Why This Works
Two's complement represents negative numbers in binary. When you convert B to two's complement, you're effectively creating -B. Then A + (-B) = A - B.
References: