After this chapter you will be able to
- solve signed-number, overflow, IEEE 754, Hamming-code and UTF-8 byte-count problems
- simplify Boolean functions and size multiplexers, adders, flip-flop circuits and counters
- work out CPU-scheduling, Banker’s, page-replacement and disk-scheduling problems step by step
- read Linux permissions, count candidate keys, normalise a relation and predict SQL output
- use the exact terms of algorithms, OOP, virtualisation, IoT, 5G, blockchain, quantum computing and AI
📌 MUST KNOW - This is extra, harder material that adds to the main book. Read Chapters 11 to 17, 20, 32 and 34 first. The main chapters answer most exam questions; this part is for the hardest ones, so do not start here.
58.1 Signed Numbers, Overflow and Floating Point
Chapter 11 gives 1’s and 2’s complement and the 2’s complement range. Exams also ask the other forms.
| Representation (n bits) | Range | Zeros | 8-bit range |
|---|---|---|---|
| Sign-magnitude | −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1) | Two (+0, −0) | −127 to +127 |
| 1’s complement | −(2ⁿ⁻¹ − 1) to +(2ⁿ⁻¹ − 1) | Two | −127 to +127 |
| 2’s complement | −2ⁿ⁻¹ to +(2ⁿ⁻¹ − 1) | One | −128 to +127 |
Overflow rule: in 2’s complement addition, overflow happens only when two numbers of the same sign give a result of the opposite sign; in hardware, the carry into the sign bit differs from the carry out of it.
- 4-bit range is −8 to +7. 5 + 4: 0101 + 0100 = 1001 (reads as −7): overflow. Carry in = 1, carry out = 0.
- (−3) + (−2): 1101 + 1110 = 1 1011; drop the carry: 1011 = −5, correct. Carry in = carry out = 1.
- A positive plus a negative number can never overflow.
- Sign extension: widen by copying the sign bit; 1011 (−5) becomes 11111011.
IEEE 754 worked example: −6.75 in single precision.
- Sign negative: S = 1.
- 6.75 = 110.11₂ = 1.1011 × 2².
- Exponent = 2 + 127 = 129 = 10000001.
- Mantissa = 1011 followed by 19 zeros (the leading 1 is the unstored hidden bit).
- 1 | 10000001 | 1011000… = C0D80000 in hex.
- Value = (−1)ˢ × 1.M × 2^(E − bias); double precision uses bias 1023.
- Exponent all 0s: zero (mantissa 0) or a denormal number. All 1s: infinity (mantissa 0) or NaN (mantissa not 0).
- 0.1 has no exact binary form (0.0001100110011…), which is why 0.1 + 0.2 is not exactly 0.3 in most languages.
★ EXAM POINT - Sign-magnitude and 1’s complement share the same range and both have two zeros. IEEE 754: single 1-8-23, bias 127; double 1-11-52, bias 1023.
58.2 Hamming Code, Excess-3 Addition and Unicode Bytes
Hamming code: for m data bits, parity bits r = smallest value with 2ʳ ≥ m + r + 1. So 4 data bits need 3 (the (7, 4) code), 8 need 4, 16 need 5, 32 need 6. Parity bits sit at positions 1, 2, 4, 8 …
Worked example (even parity), data 1011:
- Data go to positions 3, 5, 6, 7 → 1, 0, 1, 1.
- P1 checks 1, 3, 5, 7: data 1, 0, 1 (two 1s) → P1 = 0.
- P2 checks 2, 3, 6, 7: data 1, 1, 1 (three 1s) → P2 = 1.
- P4 checks 4, 5, 6, 7: data 0, 1, 1 (two 1s) → P4 = 0.
- Code word: 0110011. If bit 6 flips (0110001), the checks C4 C2 C1 give 110 = 6, the error position.
- Basic Hamming code corrects 1 error or detects 2. One extra overall parity bit gives SEC-DED, used in ECC memory.
Excess-3 addition: add the codes; for a digit that gives no carry, subtract 0011; for one that gives a carry, add 0011. 2 + 3: 0101 + 0110 = 1011, no carry, minus 0011 = 1000 = XS-3 of 5.
| Code points | UTF-8 | UTF-16 | Typical characters |
|---|---|---|---|
| U+0000 – U+007F | 1 byte | 2 bytes | English letters, digits |
| U+0080 – U+07FF | 2 bytes | 2 bytes | Accented Latin, Greek, Arabic |
| U+0800 – U+FFFF | 3 bytes | 2 bytes | Devanagari (U+0900–U+097F) |
| U+10000 – U+10FFFF | 4 bytes | 4 bytes (surrogate pair) | Most emoji |
UTF-32 always uses 4 bytes. So “Aक” takes 1 + 3 = 4 bytes in UTF-8, 4 in UTF-16 and 8 in UTF-32.