You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Everything a computer stores — a photograph, a sentence, an exam mark, a network packet — is ultimately a pattern of bits. Before we can represent images, sound, text or signed integers, we need the foundations: what kinds of numbers exist, how the same value can be written in denary (base 10), binary (base 2) and hexadecimal (base 16), and how we measure quantities of information using bits, bytes and their prefixes. This lesson builds that foundation rigorously, with many worked two-way conversions, because every later topic in data representation depends on being fluent here.
This lesson covers the opening sections of the AQA A-Level Computer Science (7517) Fundamentals of data representation area:
These ideas are assumed knowledge throughout the rest of the data-representation topic and reappear whenever capacities, address ranges or file sizes are calculated.
A-Level expects you to classify numbers precisely. The standard sets, nested inside one another, are:
| Set | Symbol | Members | Example values |
|---|---|---|---|
| Natural | N | The counting numbers (AQA treats these as starting at 0) | 0, 1, 2, 3, … |
| Integer | Z | Natural numbers plus their negatives | …, −2, −1, 0, 1, 2, … |
| Rational | Q | Any number expressible as a fraction ba with a,b∈Z and b=0 | 43, −5, 0.25, 0.3 |
| Irrational | — | Real numbers that cannot be written as a fraction of integers | π, 2, e |
| Real | R | Every rational and every irrational number — the whole continuous number line | all of the above |
The nesting is one-directional: N⊂Z⊂Q⊂R. Every natural number is an integer; every integer is rational (write 5 as 15); but not every rational is an integer, and irrationals sit inside the reals while lying outside the rationals.
A subtle exam point: a terminating or recurring decimal is always rational. 0.25=41 and 0.3=31 are both rational despite being written as decimals. Irrational numbers have decimal expansions that neither terminate nor repeat.
The same numeral can be used in two distinct ways:
In computing this distinction matters constantly. Array indices are ordinal (the element at position 3), whereas the length of the array is cardinal (it holds 10 elements). Confusing the two is the root cause of many off-by-one errors, which is exactly why AQA wants you to be conscious of the difference.
A second, related distinction is between counting and measurement. Counting is inherently discrete — you count whole items (3 files, 7 users), so the natural numbers suffice. Measurement is inherently continuous — height, time, temperature can take any value in a range, so the reals are needed. Computers, however, are finite and discrete: they cannot store a true continuum, so every "measured" real value must be approximated by a finite binary pattern. This single fact is the root of the precision limits explored in the floating-point lesson — a measured quantity such as 2 or 31 can only ever be stored as a nearby rational approximation.
Classify each value into the smallest standard set it belongs to:
| Value | Smallest set | Reasoning |
|---|---|---|
| 42 | Natural (N) | a non-negative whole number |
| −17 | Integer (Z) | whole but negative, so not natural |
| 87 | Rational (Q) | a ratio of integers, not whole |
| 0.625 | Rational (Q) | terminating decimal =85 |
| 2 | Irrational | non-terminating, non-repeating; cannot be written as ba |
| π | Irrational | likewise |
Each value also belongs to every larger set (42 is also an integer, rational and real), but the smallest set is the precise classification AQA rewards.
Exam Tip: When asked to classify a value, give the smallest set it belongs to as well as acknowledging the larger ones. −7 is "an integer (and therefore also rational and real)". Saying merely "real" is true but throws away marks. Remember the litmus test for rationality: any terminating or recurring decimal is rational; only never-ending, never-repeating expansions are irrational.
A positional number system assigns each digit a value determined by its position. In any base b, the place values are successive powers of b, and the value of a number is the weighted sum of its digits:
N=∑idi×bi
where di is the digit in position i (counting from 0 at the right-hand, least-significant end).
Denary uses ten digits, 0–9. The number 4072 means:
(4×103)+(0×102)+(7×101)+(2×100)=4000+0+70+2
This is so familiar we never think about it — but the mechanism is identical in every base.
Binary uses two digits, 0 and 1, and place values that are powers of 2. For an 8-bit number the columns are:
27128266425322416238224212201
The leftmost bit is the most significant bit (MSB) and the rightmost the least significant bit (LSB).
Hexadecimal uses sixteen digits. Since denary runs out at 9, the letters A–F stand for 10–15:
| Hex | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| Denary | 10 | 11 | 12 | 13 | 14 | 15 |
The hex place values are powers of 16:
1634096162256161161601
To avoid ambiguity we use subscripts (1012 versus 10110) or, in programming, a prefix such as 0b for binary and 0x for hex. So 0xFF is hexadecimal FF, not the denary number 255 written out — though of course they are equal.
Add the place values wherever a 1 appears. Convert 101101012:
| Bit | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Contributes | 128 | — | 32 | 16 | — | 4 | — | 1 |
128+32+16+4+1=18110
To convert 18110 back, repeatedly subtract the largest place value that fits, writing a 1 in that column and 0 where a value does not fit:
181−128=53(1 under 128) 53−32=21(1 under 32) 21−16=5(1 under 16) 5−4=1(1 under 4) 1−1=0(1 under 1)
Every other column gets a 0, giving 18110=101101012 — which matches our forward conversion. Always sanity-check by converting back.
An equivalent algorithm divides repeatedly by 2 and reads the remainders bottom-to-top. For 181:
| Division | Quotient | Remainder |
|---|---|---|
| 181÷2 | 90 | 1 |
| 90÷2 | 45 | 0 |
| 45÷2 | 22 | 1 |
| 22÷2 | 11 | 0 |
| 11÷2 | 5 | 1 |
| 5÷2 | 2 | 1 |
| 2÷2 | 1 | 0 |
| 1÷2 | 0 | 1 |
Reading the remainders from bottom to top: 101101012. Identical answer, different method — use whichever you find more reliable under exam pressure.
def denary_to_binary(n: int) -> str:
if n == 0:
return "0"
bits = ""
while n > 0:
bits = str(n % 2) + bits # prepend the remainder
n = n // 2 # integer-divide by 2
return bits
print(denary_to_binary(181)) # 10110101
Convert 70010 to hex by repeated division by 16, reading remainders bottom-to-top:
700÷16=43 remainder 12 (C) 43÷16=2 remainder 11 (B) 2÷16=0 remainder 2
Reading upward: 70010=2BC16.
Multiply each digit by its place value. For 2BC16, recall B=11 and C=12:
(2×256)+(11×16)+(12×1)=512+176+12=70010
The round trip confirms the answer.
Because 16=24, one hexadecimal digit corresponds to exactly four binary digits (one nibble). This makes conversion between binary and hex almost instant — no denary detour required.
Group the bits into nibbles from the right, padding the leftmost group with leading zeros if necessary, then translate each nibble:
Convert 11010110102. Grouping from the right gives 1101011010; pad the left group to 0011:
30011 50101 A1010
11010110102=35A16
Expand each hex digit to its 4-bit nibble. Convert C916:
C→1100,9→1001 C916=110010012
This is why hexadecimal is the preferred shorthand for memory dumps, machine code, MAC addresses and colour codes — a byte is exactly two hex digits, so eight 1s and 0s collapse to two readable characters with no loss of information.
Exam Tip: When grouping binary into nibbles, always start from the right-hand (least-significant) end. Grouping from the left is a classic error that corrupts every digit if the bit-count is not a multiple of four.
Fluency comes from recognising patterns rather than grinding every conversion from first principles. A few worth internalising:
An n-bit value of all ones is always 2n−1. So 11112=15, 111111112=255, and 111116 expanded — i.e. FFFF16 — is 216−1=65,535. Conversely a single 1 in position k is exactly 2k: 000100002=24=16. Spotting these lets you check answers instantly.
| 2n | Value | 2n | Value |
|---|---|---|---|
| 20 | 1 | 28 | 256 |
| 21 | 2 | 29 | 512 |
| 22 | 4 | 210 | 1024 |
| 23 | 8 | 216 | 65 536 |
| 24 | 16 | 220 | 1 048 576 |
| 25 | 32 | 224 | 16 777 216 |
| 26 | 64 | 230 | 1 073 741 824 |
| 27 | 128 | 232 | 4 294 967 296 |
Knowing 210=1024, 220≈1 million and 230≈1 billion makes capacity and addressing questions almost instant.
Take the denary value 429 and express it in binary and hex, then cross-check using the nibble shortcut.
Denary → binary (subtraction method): the largest power of two not exceeding 429 is 256=28.
429−256=173 (1 at 28) 173−128=45 (1 at 27) 45−32=13 (1 at 25) 13−8=5 (1 at 23) 5−4=1 (1 at 22) 1−1=0 (1 at 20)
Filling zeros elsewhere gives a 9-bit number 1101011012, i.e. 1101011012.
Binary → hex (nibble shortcut): group from the right and pad the left group to four bits — 000110101101:
10001 A1010 D1101
So 42910=1AD16.
Cross-check, hex → denary: (1×256)+(10×16)+(13×1)=256+160+13=429 ✓. Three representations of one value, each verifying the others — this is exactly the discipline that protects marks in the exam.
Denary is the human everyday base; binary is what the hardware physically stores (two stable voltage states are cheap and reliable to build); and hexadecimal is the human-friendly shorthand for binary because of the clean four-bits-per-digit relationship. Octal (base 8, three bits per digit) exists for the same shorthand reason but is far less common in modern systems. There is nothing "natural" about base 10 to a computer — we use it only because people have ten fingers.
To see the shorthand idea once more in a different base, consider octal: because 8=23, one octal digit maps to exactly three binary bits. So 110101102, grouped into threes from the right (11010110, padding the left group to 011), becomes 011010110=326, i.e. 3268. Checking back to denary: (3×64)+(2×8)+(6×1)=192+16+6=214, and 110101102=128+64+16+4+2=214 ✓. The same grouping principle that gives hex its four-bit nibbles gives octal its three-bit groups — the size of the group is just log2 of the base. This is the single unifying idea behind every binary-to-power-of-two-base conversion.
Exam Tip: If a conversion looks long, look for a shortcut: convert via hex (using nibbles) rather than doing a 16-step binary subtraction, or spot an "all ones" / "power of two" pattern. Showing a sensible method earns method marks even if the final arithmetic slips.
With n bits you can represent 2n distinct patterns. This single formula underpins capacity, range and addressing calculations throughout the course:
distinct patterns from n bits=2n
The reason a shared, standardised set of units matters cannot be overstated. If one manufacturer measured storage in groups of seven bits and another in groups of nine, files and devices simply would not interoperate. The byte (8 bits) became the universal unit early in computing history because eight bits is enough to hold one character in extended ASCII, is a convenient power of two, and divides cleanly into nibbles for hex notation. Almost every modern architecture is therefore byte-addressable — the smallest chunk of memory the processor can read or write individually is one byte — which is exactly why capacities, file sizes and memory are all quoted in bytes and their multiples rather than in raw bits. When a quantity is given in bits (network speeds, for example, are quoted in bits per second), the lower-case 'b' versus upper-case 'B' distinction becomes critical: 100 Mb/s is one-eighth of 100 MB/s, a factor-of-eight error that trips up the unwary.
Here is one of the most examined — and most misunderstood — points in the whole topic. There are two families of multiplier prefixes, and they are not equal.
Decimal (SI) prefixes use powers of 1000 (103). These are the prefixes used by storage manufacturers and by formal SI:
| Prefix | Name | Bytes |
|---|---|---|
| kB | kilobyte | 103=1,000 |
| MB | megabyte | 106=1,000,000 |
| GB | gigabyte | 109=1,000,000,000 |
| TB | terabyte | 1012=1,000,000,000,000 |
Binary (IEC) prefixes use powers of 1024 (210). These were introduced precisely to remove the historical ambiguity, and are the values an operating system typically reports:
| Prefix | Name | Bytes |
|---|---|---|
| KiB | kibibyte | 210=1,024 |
| MiB | mebibyte | 220=1,048,576 |
| GiB | gibibyte | 230=1,073,741,824 |
| TiB | tebibyte | 240≈1.0995×1012 |
Notice 210=1024 is close to but larger than 103=1000, and the gap widens with each step. By the terabyte/tebibyte level a "TB" and a "TiB" differ by nearly 10%.
This is exactly why a hard drive sold as "1 TB" shows up in the operating system as roughly 931 GiB: the manufacturer counts 1012 bytes, while the OS divides by 1024 three times.
2401012=1,099,511,627,7761,000,000,000,000≈0.909⇒1TB≈931GiB
Exam Tip: If a question uses the kibi/mebi/gibi names or explicitly says "binary prefixes", use 1024. If it uses plain "kilobyte/megabyte" you may be expected to use 1000 — but read the question: many AQA legacy questions still treat 1 kB as 1024 bytes. Where the intended convention is stated, follow it exactly and state your assumption if it is ambiguous.
Capacity questions reward laying the arithmetic out in clear steps with units at every stage. Two worked examples:
(1) How many bytes in 4 MiB? Using binary prefixes, 1 MiB=220 bytes:
4 MiB=4×220=22×220=222=4,194,304 bytes
Keeping it in index form (222) is both quicker and less error-prone than multiplying out — a good habit the examiner rewards.
(2) How many 8-bit characters fit in 16 KiB? A character here is one byte, and 16 KiB=16×1024=16,384 bytes:
1 byte/char16×210 bytes=24×210=214=16,384 characters
The 2n pattern-count formula also governs how much memory a processor can address. If an address bus is n bits wide, it can specify 2n distinct addresses; if each address holds one byte, the maximum directly addressable memory is 2n bytes. For example:
| Address bus width | Addressable locations | Capacity (byte-addressed) |
|---|---|---|
| 16-bit | 216=65,536 | 64 KiB |
| 20-bit | 220 | 1 MiB |
| 32-bit | 232 | 4 GiB |
| 64-bit | 264 | 16 EiB (effectively unlimited today) |
This is the historical reason 32-bit operating systems were capped at 4 GiB of usable RAM — 232 byte-addresses is the hard ceiling of a 32-bit address bus — and why the move to 64-bit addressing was necessary. It is also why memory addresses are quoted in hexadecimal: a 32-bit address is exactly 8 hex digits (e.g. 0x7FFFFFFF), neatly two per byte, looping us right back to the binary-hex nibble shortcut. Bits, bytes, bases and units are one connected system, which is precisely the synoptic understanding this lesson is building toward.
#FF8800), two per channel.integer, real/float and boolean data types you declare in code.A games console stores a 24-bit colour as three 8-bit channels (red, green, blue). A texture file is described as being 512 KiB in size. (Total: 9 marks)
(a) Convert the hexadecimal colour value 2F to (i) binary and (ii) denary, showing your working. [3]
(b) Convert the bit pattern 11100110 to hexadecimal. [2]
(c) State how many distinct colours can be represented using 24 bits, giving your answer as a power of 2 and as an approximate decimal value. [2]
(d) Express 512 KiB exactly in bytes, and explain why this differs from "512 kB" interpreted with decimal prefixes. [2]
AO breakdown:
| Mark | AO | Awarded for |
|---|---|---|
| 1 | AO2 | (a)(i) Correct nibble expansion 2 → 0010, F → 1111 |
| 2 | AO1 | (a)(ii) Correct hex place values (16 and 1) used |
| 3 | AO2 | (a)(ii) Correct denary value 47 |
| 4 | AO2 | (b) Correct grouping into 1110 and 0110 |
| 5 | AO2 | (b) Correct hex digits giving E6 |
| 6 | AO1 | (c) Stating 224 distinct colours |
| 7 | AO2 | (c) Approximate decimal value ≈ 16.7 million |
| 8 | AO2 | (d) 512 KiB = 524 288 bytes |
| 9 | AO3 | (d) Explaining the binary-prefix reason (×1024 not ×1000) |
AO split: AO1 = 2, AO2 = 6, AO3 = 1.
(a)(i) 2 is 0010 and F is 1111, so 2F is 00101111. (ii) F is 15 and 2 is in the 16s column. 2×16=32 and 15×1=15, so 32+15=47. (b) Split 11100110 into 1110 and 0110. 1110 is E and 0110 is 6, so it is E6. (c) 24 bits gives 224 colours, which is about 16 million. (d) 512 KiB is 512×1024=524288 bytes. It is bigger than 512 kB because KiB uses 1024.
Examiner-style commentary: Marks 1–6 and mark 8 are all secured, and the candidate reaches the 224 statement for mark 6. Mark 7 is borderline — "about 16 million" is close but imprecise; a stronger answer pins it to ≈16.7 million. Mark 9 is not awarded: the candidate states KiB uses 1024 but never contrasts it with the decimal interpretation (×1000 → 512 000 bytes), so the explanation of the difference is incomplete. Around 7/9.
(a)(i) Expanding each hex digit: 2 → 0010, F → 1111, so 2F16=001011112. (ii) Place values 161 and 160: (2×16)+(15×1)=32+15=4710. (b) Grouping from the right: 11100110; 1110=E, 0110=6, so 111001102=E616. (c) 224=16,777,216 distinct colours (≈16.7 million). (d) 512 KiB=512×210=524,288 bytes. Interpreted as decimal "512 kB" it would be 512×1000=512,000 bytes, so the binary figure is 12 288 bytes larger.
Examiner-style commentary: All nine marks are within reach. The conversions are flawless and the candidate gives the exact 224 value rather than a vague "16 million". The decimal contrast for mark 9 is present but stated arithmetically rather than explained in principle — a top-band answer would add why the two prefix systems exist.
(a)(i) Each hex digit maps to one nibble: 2→0010, F→1111, hence 2F16=001011112. (ii) Using hex place values: (2×161)+(15×160)=32+15=4710; a back-check from the binary gives 32+8+4+2+1=47. (b) Grouping the byte from the right into nibbles gives 11100110; since 1110=14=E and 0110=6, we have 111001102=E616. (c) With 24 bits there are 224=16,777,216 distinct patterns, so ≈16.7 million colours — this is why 24-bit colour is called "true colour", being beyond the discriminating power of the human eye. (d) A kibibyte is 210=1024 bytes, so 512 KiB=512×1024=524,288 bytes exactly. The decimal kilobyte uses 103=1000, giving 512,000 bytes for "512 kB" — a difference of 12 288 bytes (≈2.4%). The two systems coexist because storage manufacturers adopted the SI powers of ten while memory and operating systems naturally count in powers of two (addresses are binary); the IEC kibi/mebi prefixes were introduced precisely to remove this ambiguity.
Examiner-style commentary: Full marks. The discriminators are the exact 224 value (mark 7), the explicit decimal-vs-binary byte counts and the principled reason for the two prefix families (marks 8–9, including AO3 evaluation), and the disciplined back-check in (a)(ii). The candidate demonstrates that hex, binary and units of information are one connected system rather than isolated tricks.
chmod 755). Base-64 encoding packs binary data into printable ASCII for email attachments and data URIs — investigate how 3 bytes (24 bits) map to 4 base-64 characters.This content is aligned with the AQA A-Level Computer Science (7517) specification.