Number bases
Computers store everything as bits. Each binary place value doubles: 128, 64, 32, 16, 8, 4, 2, 1 for one byte.
Binary to denary: add the place values that hold a 1. 11010011 = 128 + 64 + 16 + 2 + 1 = 211.
Denary to binary: subtract the largest place values that fit. 100 = 64 + 32 + 4, so 100 = 01100100.
Hexadecimal (base 16) uses 0 to 9 then A=10 to F=15. One hex digit is exactly 4 bits, so split a byte into two nibbles: 1101 0011 = D3. To go from hex to denary, multiply the first digit by 16: D3 = 13 x 16 + 3 = 211. Programmers use hex because it is short, easy to convert to binary and less error-prone to read (colours #RRGGBB, memory addresses, MAC addresses).
Negative numbers: two's complement
The leftmost bit has a negative place value (-128 in 8 bits). To encode -38: write +38 = 00100110, flip every bit to 11011001, add 1 to get 11011010. Check: -128 + 64 + 16 + 8 + 2 = -38.
8-bit range: -128 to +127. If two positives add to something above 127, the sign bit flips and the result looks negative: 01100100 (100) + 01000000 (64) = 10100100, which reads as -92. This is overflow.
Fractions are stored in floating point, which cannot represent most decimals exactly; compare floats with a tolerance, e.g. abs(a - b) < 1e-9, not with ==.
Text, images and sound
- Text: each character maps to a number. ASCII uses 7 bits (128 characters;
A= 65,a= 97). Unicode covers every writing system and emoji; UTF-8 stores ASCII characters in 1 byte and others in 2 to 4. - Bitmap images: size in bits = width x height x colour depth. A 800 x 600 image at 24-bit colour is 800 x 600 x 3 = 1 440 000 bytes. More bits per pixel means more colours (\(2^n\)).
- Sound: the wave is sampled at regular intervals. Size in bits = sample rate x bit depth x channels x seconds. 5 s of mono at 8000 Hz, 8-bit: 8000 x 1 x 1 x 5 = 40 000 bytes.
Logic gates
| A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
NOT simply inverts its single input.
Building logic diagrams from a scenario
A pump P runs when the tank is low (L) and the valve is open (V), unless an emergency stop (E) is pressed: \(P = (L \cdot V) \cdot \overline{E}\). Draw one gate per operator, working from the inputs towards the output, and check with a truth table. With 3 inputs a table has \(2^3 = 8\) rows; list them in binary counting order 000 to 111 so none is missed.
| L | V | E | L AND V | NOT E | P |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
Simplifying Boolean expressions (HL)
Useful laws: \(A + A \cdot B = A\) (absorption), \(A + \overline{A} = 1\), \(A \cdot \overline{A} = 0\), \(A \cdot 1 = A\), distribution \(A \cdot B + A \cdot C = A \cdot (B + C)\), and De Morgan: \(\overline{A \cdot B} = \overline{A} + \overline{B}\), \(\overline{A + B} = \overline{A} \cdot \overline{B}\).
Worked example: \(X \cdot Y + X \cdot \overline{Y} + \overline{X} \cdot \overline{Y}\)
- Factor the first two terms: \(X \cdot (Y + \overline{Y}) = X\)
- Now \(X + \overline{X} \cdot \overline{Y}\), which simplifies (redundancy law) to \(X + \overline{Y}\)
Verify with a truth table: the only row giving 0 is X = 0, Y = 1 in both forms. NAND and NOR are universal: tying both inputs of a NAND together gives NOT, so any circuit can be built from NAND alone.
Common mistakes
- Reading the hex digit order backwards, or forgetting A = 10.
- In two's complement, flipping the bits but forgetting to add 1.
- Mixing bits and bytes in file-size answers (divide by 8 at the end).
- Forgetting the number of channels for stereo sound (x 2).
- Truth tables with missing or repeated rows.
Exam tips
- Show working for every conversion; method marks are common.
- State units (bits, bytes, KB) and whether you use 1000 or 1024.
- For scenario logic, define each input letter before writing the expression.