Two's Complement & Floating Point
Computers must represent negative numbers and decimal numbers using only binary. Two's complement is the standard method for negative integers, while floating point representation handles decimals. Both are essential for understanding how real-world data is stored in a binary system.
Learning Objectives
- 12.3.5.3 Represent negative numbers using two's complement
- 12.3.5.4 Represent real numbers using floating point (mantissa and exponent)
Part 1: Two's Complement
Two's complement is the standard way computers store negative integers. The most significant bit (MSB) acts as the sign bit: 0 = positive, 1 = negative.
Range of Values (8-bit)
| Representation | Minimum | Maximum | Range |
|---|---|---|---|
| Unsigned 8-bit | 0 | 255 | 0 to 2⁸ − 1 |
| Two's complement 8-bit | −128 | +127 | −2⁷ to 2⁷ − 1 |
Converting to Two's Complement
✓ Method: Convert −45 to 8-bit two's complement
Step 1: Write +45 in binary
45 = 00101101
Step 2: Flip all the bits (one's complement)
00101101 → 11010010
Step 3: Add 1
11010010
+ 1
────────
11010011
Result: −45 in two's complement = 11010011✓ Converting Back: What is 11010011 in denary?
MSB is 1 → negative number
Method 1: Flip & add 1, then negate
11010011 → flip → 00101100 → add 1 → 00101101 = 45
Answer: −45
Method 2: Use negative place value for MSB
Place values: -128 64 32 16 8 4 2 1
Binary: 1 1 0 1 0 0 1 1
= -128 + 64 + 16 + 2 + 1 = -45 ✓Two's Complement Arithmetic
✓ Adding: 35 + (−20) = 15
35 = 00100011
−20 = 11101100 (two's complement of 20)
00100011
+ 11101100
────────
100001111 ← 9 bits! Discard carry (overflow bit)
00001111 = 15 ✓✓ Subtracting: 50 − 75 = −25
50 − 75 = 50 + (−75)
50 = 00110010
−75 = 10110101 (two's complement of 75)
00110010
+ 10110101
────────
11100111
MSB is 1 → negative. Flip & add 1:
11100111 → 00011000 → 00011001 = 25
Answer: −25 ✓Part 2: Floating Point Representation
Floating point stores real (decimal) numbers by separating them into two parts:
| Component | Purpose | Analogy |
|---|---|---|
| Mantissa | Stores the significant digits (precision) | The "number part" of scientific notation |
| Exponent | Stores the power (position of binary point) | The "× 10ⁿ" part of scientific notation |
Scientific Notation Analogy
Just like 6,500,000 = 6.5 × 10⁶ in denary, binary floating point works the same way:
Value = Mantissa × 2Exponent
Floating Point Worked Examples
✓ Convert 0.1011 × 2³ to denary
Given: Mantissa = 0.1011, Exponent = 011 (= 3 in two's complement)
Step 1: Move binary point right by exponent (3 places)
0.1011 → 0101.1
Step 2: Convert to denary
Fixed point: 0101.1
= 4 + 1 + 0.5 = 5.5
Result: 0.1011 × 2³ = 5.5✓ Convert 6.75 to floating point (8-bit: 5-bit mantissa, 3-bit exponent)
Step 1: Convert 6.75 to fixed-point binary
6 = 110
0.75 = 0.5 + 0.25 = .11
6.75 = 110.11
Step 2: Normalise — shift point left until format is 0.1xxxx
110.11 → 0.11011 × 2³
(shifted left 3 places → exponent = 3)
Step 3: Encode
Mantissa (5 bits): 01101 (0.11011, truncated to 5 bits)
Exponent (3 bits): 011 (3 in two's complement)
Result: 01101 011Normalisation
| Aspect | Normalised Form |
|---|---|
| Positive number | Mantissa starts with 0.1 (first two bits: 0, 1) |
| Negative number | Mantissa starts with 1.0 (first two bits: 1, 0) |
| Why normalise? | Maximises precision — no wasted leading zeros |
Precision vs Range Trade-off
More mantissa bits → more precision (more decimal places). More exponent bits → larger range (bigger/smaller numbers). Increasing one means decreasing the other.
Pitfalls & Common Errors
Forgetting to Add 1 in Two's Complement
The process is: (1) flip all bits, THEN (2) add 1. Forgetting step 2 gives one's complement, not two's complement — you'll be off by 1.
Discarding the Carry in Addition
When adding two values in two's complement and the result has an extra (9th) bit, the carry is discarded — this is normal, not overflow. True overflow is when adding two positives gives a negative, or two negatives give a positive.
Shifting Binary Point Wrong Way
Positive exponent → shift binary point right. Negative exponent → shift left. Getting this backwards gives the wrong value.
Pro-Tips for Exams
Two's Complement Strategy
- Shortcut: scan from right, keep all bits up to and including the first 1, then flip all remaining bits
- Always check MSB: 0 = positive, 1 = negative
- Subtraction = add the negative: A − B = A + (−B)
Floating Point Strategy
- Always state: mantissa gives precision, exponent gives range
- Normalisation = mantissa starts 0.1 (positive) or 1.0 (negative)
- Show your working clearly: convert to fixed point first, then normalise
Graded Tasks
Convert to 8-bit two's complement: (a) −56 (b) −100 (c) −1
Convert from 8-bit two's complement to denary: (a) 11001110 (b) 10000001 (c) 11111111
Perform in two's complement: 40 + (−65). Show all working.
Convert 13.25 to normalised floating point (8-bit: 5-bit mantissa, 3-bit exponent).
Explain the trade-off between the number of bits allocated to the mantissa vs the exponent. What happens to precision and range?