CIE AS & A Level Computer Science, section 1.1 (Data representation)
The number bases
| System | Base | Digits used |
|---|---|---|
| Denary (decimal) | 10 | 0 to 9 |
| Binary | 2 | 0 and 1 |
| Hexadecimal | 16 | 0 to 9 and A to F |
In hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Binary to denary
Add the place values (128, 64, 32, 16, 8, 4, 2, 1 for an 8-bit number) wherever there is a 1.
Denary to binary
Subtract the largest power of 2 that fits, or divide repeatedly by 2 and read the remainders from the bottom up.
Hexadecimal
Hexadecimal is a shorthand for binary: each hex digit stands for 4 bits (a nibble). Split the binary number into groups of 4 from the right.
Binary Coded Decimal (BCD)
In BCD, each denary digit is stored as its own 4-bit binary code. It is not the same as the binary value of the whole number.
Where they are used
- Hexadecimal: memory addresses, colour codes (such as #FF8000), MAC addresses and error codes. It is shorter and easier for people to read and less error-prone than long binary strings.
- BCD: digital clocks and calculators, and financial systems, where each digit is displayed or processed separately and exact decimal values are needed.
Common mistake: treating BCD as ordinary binary. in BCD is (three groups), while in binary is . Also, remember to convert each hex digit to exactly 4 bits, including leading zeros.
Exam tip: show your working for conversions (place values or repeated division). For hexadecimal questions, say it is used because it is a compact way to represent binary and is easier to read and write.
Check yourself
Convert to hexadecimal.
and , so .
Write 47 in BCD.
.
Give one use of hexadecimal.
Any of: colour codes, memory addresses, MAC addresses, error codes. It is shorter than binary and easier to read.