Computers work in powers of two. Two families of prefixes are used when describing memory or data sizes.
| Prefix (binary) | Symbol | Value |
|---|---|---|
| kibi | Ki | 1 KiB = 210 bytes = 1 024 B |
| mebi | Mi | 1 MiB = 220 bytes = 1 048 576 B |
| gibi | Gi | 1 GiB = 230 bytes = 1 073 741 824 B |
| tebi | Ti | 1 TiB = 240 bytes |
For everyday discussion the decimal prefixes kilo (k = 10³), mega (M = 10⁶) and giga (G = 10⁹) are also used, but they do not map exactly to the binary values. Knowing the difference is essential when converting file‑size, bandwidth or storage‑requirement figures.
Cambridge examinations require you to move fluently between binary, decimal, hexadecimal and Binary‑Coded Decimal (BCD). The following pseudo‑code is short enough to be memorised.
function binToDec(b):
dec = 0
for each bit from left‑most to right‑most:
dec = dec * 2 + bit
return dec
function decToBin(n):
bits = []
while n > 0:
bits.append(n % 2) // remainder is next bit
n = n // 2
return reverse(bits) // most‑significant bit first
function decToBCD(n):
bcd = []
for each decimal digit d in string representation of n:
bcd.append( binary representation of d using 4 bits )
return concatenate(bcd)
All binary arithmetic in the syllabus is performed on fixed‑width words (usually 8‑, 16‑ or 32‑bit). The rules below are sufficient for exam questions.
Example (8‑bit): 1101 0110₂ (214) + 0011 1011₂ (59)
1101 0110 + 0011 1011 ------------ 0000 11101 (carry out of MSB = 1 → result = 0010 11101₂ = 13, overflow)
Example (8‑bit): +25 – 45
0001 1001 (+25) 1101 0011 (two’s‑complement of 45 = invert 0010 1101 → 1101 0010, +1 → 1101 0011) ---------- 1110 1100 (result = –20, MSB = 1, no overflow because carries into/out of sign bit are equal)
Text is stored as numeric codes. The two most common systems are:
| Encoding | Bits per code point | Range | Typical use in exams |
|---|---|---|---|
| ASCII | 7 bits (usually stored in an 8‑bit byte) | 0 – 127 (basic Latin) | Identify control characters, convert between character and decimal/hex. |
| Unicode (UTF‑8) | 1‑4 bytes per code point | 0 – 0x10FFFF (all world scripts) | Explain why a character may need more than one byte. |
First 32 ASCII codes are control characters (e.g., 0x00 NUL, 0x0A LF). Knowing these values helps when analysing protocol headers or debugging text‑based data.
BCD stores each decimal digit (0‑9) as a separate 4‑bit nibble. It uses more bits than a pure binary representation but guarantees a direct decimal view, which is valuable in many real‑world systems.
When adding BCD numbers each nibble must stay ≤ 9. After a normal binary addition, any nibble that exceeds 9 is corrected by adding 6 (0x06). This is known as the “BCD correction” step.
Example: Add 0x27 (decimal 27) and 0x58 (decimal 58).
0010 0111 (0x27) + 0101 1000 (0x58) ------------ 0111 1111 (binary sum = 0x7F) Nibble‑wise correction: lower nibble = 0xF (>9) → add 0x6 → 0xF + 0x6 = 0x15 → write 0x5, carry 1 upper nibble = 0x7 + carry 1 = 0x8 (≤9, no further correction) Result = 0x85 → decimal 85 (correct answer).
Overflow is detected when a corrected nibble still exceeds 9 after the correction step, or when a carry is generated out of the most‑significant digit.
Hexadecimal (base‑16) uses the symbols 0‑9 and A‑F, each representing a 4‑bit binary group (a nibble). It is the preferred notation for low‑level programming, debugging and hardware documentation.
#RRGGBB where each pair of hex digits gives the intensity of red, green and blue.0x3F).The syllabus expects you to understand how images, video and sound are stored.
Two broad categories are required for the exam.
Original byte stream: AAABBBBBCCDDDDDDDD
RLE representation (value, count): (A,3)(B,5)(C,2)(D,8)
If the count field is stored in a single byte, the compressed size is 8 bytes versus the original 16 bytes – a 50 % reduction.
| Aspect | Binary‑Coded Decimal (BCD) | Hexadecimal |
|---|---|---|
| Primary goal | Exact decimal representation | Compact representation of binary data |
| Typical domain | Finance, time‑keeping, user‑entered numeric entry | Systems programming, hardware design, networking |
| Storage efficiency | 4 bits per decimal digit (inefficient for large numbers) | 4 bits per hex digit (covers 0‑15 values) |
| Human readability | Directly readable as decimal digits | Readable for engineers familiar with binary groups |
| Common example | Amount $123.45 → 0001 0010 0011 0100 0101 (BCD) |
Memory address 0x3FA7 → binary 0011 1111 1010 0111 |
Display required: 14:35
00010100001101010001 0100 0011 0101 (BCD representation of 14:35).Peripheral register at address 0x1A3C. Set the low byte to 0xFF while preserving the high byte.
unsigned short *reg = (unsigned short *)0x1A3C;
*reg = (*reg & 0xFF00) | 0x00FF; // keep high byte, set low byte to 0xFF
This demonstrates the convenience of hex literals for bit‑masking and address manipulation.
Compute -12 + 27 using 8‑bit two’s‑complement.
-12 → 1111 0100 (invert 0000 1011 → 1111 0100, add 1 → 1111 0101) 27 → 0001 1011 ---------------- 0000 1110 = +14 (correct result, no overflow)
Row (binary) = 1111000011110000
RLE (value, count): (1,4)(0,4)(1,4)(0,4)
Original size = 16 bits; compressed size = 4 pairs × (1 bit + 4 bits for count) = 20 bits – in this tiny example the overhead is larger, illustrating that RLE is only efficient when long runs occur.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.