Appearance
C1 · Number Systems
Spec reference: Section C1 - How Data is Represented Key idea: Understand binary, BCD, and how to perform binary arithmetic including negative and floating point numbers.
Units of digital data
| Unit | Size |
|---|---|
| Bit | Single binary digit: 0 or 1 |
| Nibble | 4 bits |
| Byte | 8 bits |
| Kilobyte (KB) | 1,024 bytes |
| Megabyte (MB) | 1,024 KB |
| Gigabyte (GB) | 1,024 MB |
| Terabyte (TB) | 1,024 GB |
Number systems
Binary (Base 2)
Uses only 0 and 1. Each position is a power of 2.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 |
This binary number = 64 + 16 + 8 + 1 = 89
Hexadecimal (Base 16)
Uses digits 0-9 and letters A-F. Each hex digit represents 4 bits (a nibble).
| Hex | Binary | Decimal |
|---|---|---|
| 0-9 | 0000-1001 | 0-9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Used in memory addresses, colour codes (HTML), and MAC addresses because it is more compact than binary.
Binary Coded Decimal (BCD)
Each decimal digit is stored as its 4-bit binary equivalent.
Example: 47 in BCD:
- 4 = 0100
- 7 = 0111
- BCD representation: 0100 0111
Used in systems where exact decimal representation is important, such as financial systems and digital clocks.
Binary arithmetic
Addition
Rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (write 0, carry 1), 1+1+1=11 (write 1, carry 1)
0 1 1 0 1 (13)
+ 0 0 1 1 1 ( 7)
-----------
1 0 1 0 0 (20)Subtraction
Using two's complement (see below) is the standard method.
Multiplication
Shift left and add. Multiplying by 2 is a single left shift.
Division
Shift right and subtract. Dividing by 2 is a single right shift.
Representing negative numbers: Two's Complement
Two's complement is the standard way computers represent negative integers.
To convert a positive binary number to its negative equivalent:
- Invert all bits (flip 0s to 1s and 1s to 0s).
- Add 1 to the result.
Example: Represent -6 in 8-bit two's complement.
- +6 in binary: 0000 0110
- Invert: 1111 1001
- Add 1: 1111 1010
So -6 = 1111 1010 in two's complement.
The most significant bit (MSB) acts as the sign bit: 0 = positive, 1 = negative.
| 8-bit two's complement range | -128 to +127 |
Floating point numbers
Floating point allows computers to represent very large or very small numbers.
A floating point number has two parts:
- Mantissa: The significant digits.
- Exponent: The power of 2 by which the mantissa is multiplied.
Example (simplified): The number 0.001011 x 2^5 in normalised form:
- Mantissa: 0.101100
- Exponent: 5
Exam point
Normalised floating point means the mantissa is adjusted so the first significant digit is immediately after the binary point (for positive: 0.1..., for negative: 1.0...). This maximises precision.
Trade-offs:
- More bits for the mantissa: greater precision.
- More bits for the exponent: greater range.
- Rounding errors occur because not all decimal values can be represented exactly in binary floating point.
Summary
| Term | Meaning |
|---|---|
| Bit | The smallest unit of data, 0 or 1 |
| Two's complement | Method for representing negative integers in binary |
| BCD | Each decimal digit stored as 4 binary bits |
| Mantissa | The significant digits in a floating point number |
| Exponent | The power applied to the mantissa in floating point |
| Overflow | When a result is too large to be stored in the available bits |