Computers need to represent negative numbers in binary. Two methods are used: sign and magnitude and two's complement. Cambridge 0478 requires you to know both.
The most significant bit (MSB) — the leftmost bit — is used as a sign bit: 0 means positive, 1 means negative. The remaining bits represent the magnitude (size) of the number.
| Binary | Sign bit | Magnitude | Value |
|---|---|---|---|
| 00000101 | 0 (positive) | 0000101 | +5 |
| 10000101 | 1 (negative) | 0000101 | –5 |
Problem with sign and magnitude: There are two representations of zero (+0 = 00000000, –0 = 10000000), and arithmetic is complex to implement in hardware.
Two's complement is the method actually used in modern computers. It allows straightforward binary addition for both positive and negative numbers.
| Bit position | –128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Example | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 0 |
Example: 10110100 in two's complement = –128 + 32 + 16 + 4 = –76
Example: Convert +13 to –13 in two's complement (8-bit):
Add as normal binary. Any carry out of the MSB is discarded.
Example: 5 + (–3) = 2
5 questions · 11 marks · instantly marked
| Term | Definition |
|---|
Timed exam-style conditions.