Unit 3
Data representation
How a computer represents numbers and characters as bits, and how it does arithmetic and logic on them: number systems and conversions, signed integers and two's complement, character codes, binary arithmetic and bitwise operations. It is a Grade 12 unit that carries three to five Paper I marks every year, and Paper II Part A sometimes adds a multi-step conversion or subtraction.
What the exam asks
Three to five Paper I marks every year: a decimal fraction to binary or hex (2024 Q7, 2025 Q10, 2026 Q9); octal and hex conversion statements to check (2024 Q8-9, 2026 Q8); binary addition, register overflow and two's complement (2024 Q11, 2025 Q12, 2026 Q6); and character codes, such as building a word in ASCII, comparing ASCII and EBCDIC storage, and reading Unicode hex (2024 Q10, 2025 Q11, 2026 Q7). Paper II Part A asked for subtraction by adding the two's complement in 2024 (Q10b).
The unit on one page
Data representation
Number systems
Base and place valueConversionsSigned integersTwo's complement
Character codes
BCD: 4-bit digitsASCII: 7 bitsEBCDIC: IBM, 8 bitsUnicode: every script
Binary arithmetic
Carry and borrowSubtract by complementOverflowBitwise AND, OR, XOR
3.1 Number systems and representation of numbers
- A number system is set by its base (radix): the number of different digits it uses. Decimal is base 10 (0-9), binary base 2 (0 and 1), octal base 8 (0-7) and hexadecimal base 16 (0-9 and A-F, where A = 10 and F = 15).
- Place value: each position is a power of the base. Left of the point the powers are 0, 1, 2 and so on; right of the point they are −1, −2 and so on. In 1011.01₂ the places are 2³ 2² 2¹ 2⁰ . 2⁻¹ 2⁻².
- Computers use binary because their circuits have two stable states (high and low voltage, on and off), which are simple to build and hard to confuse.
- Octal and hexadecimal are short ways of writing binary: one octal digit stands for exactly 3 bits and one hex digit for exactly 4 bits. Hex is used for memory addresses, colour codes (#FF0000) and MAC addresses.
- Decimal to any base: divide the whole part by the base again and again and read the remainders from the bottom up. Multiply the fraction part by the base again and again and read the whole-number parts from the top down.
- Any base to decimal: multiply each digit by its place value and add. 2D.6₁₆ = 2 × 16 + 13 × 1 + 6 × 1/16 = 45.375.
- Binary to octal or hex: group the bits in 3s (octal) or 4s (hex) outwards from the binary point, adding 0s at the far left and the far right where a group is short. Octal to hex, or hex to octal, goes through binary.
- Some decimal fractions have no exact binary form: 0.1₁₀ = 0.000110011…₂ repeats for ever, so the computer stores an approximation.
- Units of data: a bit is one 0 or 1, a nibble is 4 bits and a byte is 8 bits. 1 KB = 2¹⁰ = 1024 bytes, 1 MB = 2²⁰ bytes, 1 GB = 2³⁰ bytes and 1 TB = 2⁴⁰ bytes. n bits make 2ⁿ patterns, so unsigned values run from 0 to 2ⁿ − 1 (0 to 255 in 8 bits).
- Signed integers: the MSB (most significant bit, the leftmost) is the sign bit, 0 for positive and 1 for negative. There are three methods: sign-magnitude, one's complement and two's complement. A positive number is written the same way in all three.
- To write −N in two's complement: write +N in the full number of bits, invert every bit (this is the one's complement), then add 1. With n bits the range is −2ⁿ⁻¹ to +2ⁿ⁻¹ − 1, which is −128 to +127 in 8 bits.
- Two's complement is preferred for arithmetic: it has only one zero, subtraction is done by adding the complement so one adder circuit does both jobs, and the sign bit needs no special handling (the carry out of the MSB is simply dropped).
Key terms
- Base (radix)
- The number of different digits a number system uses: binary 2, octal 8, decimal 10, hexadecimal 16.
- MSB / LSB
- Most significant bit: the leftmost bit, with the highest place value. Least significant bit: the rightmost bit, with place value 2⁰.
- Sign bit
- The MSB of a signed number: 0 means positive, 1 means negative.
- Sign-magnitude
- A sign bit followed by the size of the number in binary. −5 in 8 bits is 1000 0101.
- One's complement
- Every bit of the positive number inverted. −5 in 8 bits is 1111 1010.
- Two's complement
- The one's complement plus 1. −5 in 8 bits is 1111 1011. The method computers use for signed integers.
- Nibble
- A group of 4 bits: exactly one hexadecimal digit.
Decimal, binary, octal and hexadecimal from 0 to 15
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
Powers of 2 to know by heart
| Powers | Values |
|---|---|
| 2⁰, 2¹, 2², 2³, 2⁴ | 1, 2, 4, 8, 16 |
| 2⁵, 2⁶, 2⁷, 2⁸ | 32, 64, 128, 256 |
| 2¹⁰, 2¹⁶ | 1024, 65 536 |
| 2⁻¹, 2⁻², 2⁻³, 2⁻⁴ | 0.5, 0.25, 0.125, 0.0625 |
Conversion methods
| From → to | Method | Example |
|---|---|---|
| Decimal → binary, whole part | Divide by 2 again and again; read the remainders from the bottom up | 84 → 1010100₂ |
| Decimal → binary, fraction part | Multiply by 2 again and again; read the whole-number parts from the top down | 0.375 → 0.011₂ |
| Any base → decimal | Multiply each digit by its place value and add | 157₈ = 64 + 40 + 7 = 111 |
| Binary → octal | Groups of 3 bits outwards from the point | 101 101.011₂ = 55.3₈ |
| Binary → hex | Groups of 4 bits outwards from the point | 0010 1101.0110₂ = 2D.6₁₆ |
| Octal or hex → binary | Replace each digit with its 3 or 4 bits | 7F₁₆ = 0111 1111₂ |
| Octal ↔ hex | Go through binary | 377₈ = 011 111 111₂ = 1111 1111₂ = FF₁₆ |
Signed integers in 8 bits
| Method | +5 | −5 | 8-bit range | Zeros |
|---|---|---|---|---|
| Sign-magnitude | 0000 0101 | 1000 0101 | −127 … +127 | Two: 0000 0000 and 1000 0000 |
| One's complement | 0000 0101 | 1111 1010 | −127 … +127 | Two: 0000 0000 and 1111 1111 |
| Two's complement | 0000 0101 | 1111 1011 | −128 … +127 | One: 0000 0000 |
Worked example
Convert 45.375₁₀ to binary, octal and hexadecimal. Then write −45 in 8-bit two's complement.
- Split the number: whole part 45, fraction 0.375. Convert each part on its own.
- Whole part, divide by 2: 45 ÷ 2 = 22 r 1; 22 ÷ 2 = 11 r 0; 11 ÷ 2 = 5 r 1; 5 ÷ 2 = 2 r 1; 2 ÷ 2 = 1 r 0; 1 ÷ 2 = 0 r 1. Read the remainders upwards: 101101.
- Fraction, multiply by 2: 0.375 × 2 = 0.75, write 0; 0.75 × 2 = 1.5, write 1 and keep 0.5; 0.5 × 2 = 1.0, write 1, nothing is left. Read downwards: .011
- So 45.375₁₀ = 101101.011₂. Check: 32 + 8 + 4 + 1 + 0.25 + 0.125 = 45.375.
- Octal: group in 3s outwards from the point: 101 101 . 011 = 5 5 . 3, so 55.3₈.
- Hex: group in 4s outwards from the point and fill with 0s: 0010 1101 . 0110 = 2 D . 6, so 2D.6₁₆. The fraction is filled on the right: .011 becomes .0110 = 6, not .0011 = 3.
- −45: write +45 in 8 bits: 0010 1101. Invert every bit: 1101 0010. Add 1: 1101 0011.
- Check by giving the MSB the place value −128: −128 + 64 + 16 + 2 + 1 = −45.
45.375₁₀ = 101101.011₂ = 55.3₈ = 2D.6₁₆, and −45 = 1101 0011 in 8-bit two's complement.
Remember
Two's complement: write the full width, invert every bit, add 1. Check any conversion by turning it back into decimal.
Memory trick
Divide, read up; multiply, read down. For two's complement there is a shortcut from the right: copy every bit up to and including the first 1, then flip the rest (0000 0101 → 1111 1011).
In the exam
Paper I builds its five options from the usual slips: remainders read top down, a fraction filled on the wrong side, inverting without adding 1, the wrong bit width. Convert your answer back to decimal before you shade it. In Paper II write every division and multiplication line, because the method carries marks.
