Unsigned binary can only represent non-negative numbers. To represent negative integers in hardware, computers use two's complement — the standard method used by virtually all modern processors.
In two's complement, the MSB (most significant bit) has a negative weight:
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Range for n-bit two's complement: −2^(n−1) to 2^(n−1)−1. For 8 bits: −128 to +127.
Example: 11110010 = −128+64+32+16+2 = −14
Method — invert all bits, then add 1:
| Step | Binary | Decimal |
|---|---|---|
| Start: +23 | 00010111 | +23 |
| Invert all bits | 11101000 | — |
| Add 1 | 11101001 | −23 |
Verify: −128+64+32+8+1 = −128+105 = −23 ✓
Subtraction A − B is performed as A + (two's complement of B). This avoids separate subtraction circuitry.
| Step | Binary |
|---|---|
| +45 | 00101101 |
| 28 → invert | 11100011 |
| Add 1 (−28) | 11100100 |
| 45 + (−28) | 00010001 |
Result: 00010001 = 16+1 = 17 ✓ (discard overflow carry)
An alternative representation: use the MSB as a sign bit (1=negative), remaining bits represent magnitude. Problem: two representations of zero (+0 and −0), and arithmetic is more complex. Not used in practice — two's complement is preferred.
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes