Data representation
Cambridge IGCSE Computer Science 0478 · Paper 1 · Topic 1
Worth about 18 of the 75 marks on a typical Paper 1. Almost every paper opens with this topic.
1. Why computers use binary
Everything a computer stores or processes, whether numbers, text, photos, music or video, is represented as binary: patterns of only two digits, 0 and 1. A single binary digit is called a bit. Data must be converted to binary before a computer can process it.
Computers use binary because their circuits are built from switches (transistors) with only two states, on and off. Data is processed by logic gates and stored in registers, which hold a fixed number of bits.
2. Denary, binary and hexadecimal
Hexadecimal and denary are just easier ways for people to read the same values the computer stores in binary.
| System | Base | Digits used | Who uses it |
|---|---|---|---|
| Denary | 10 | 0–9 | People, everyday counting |
| Binary | 2 | 0, 1 | The computer, internally |
| Hexadecimal | 16 | 0–9, A–F (A = 10 … F = 15) | Programmers, as a short form of binary |
3. Converting binary and denary
Each binary column is worth double the one to its right.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
0110 1001 = 64 + 32 + 8 + 1 = 105. The largest 8-bit value is 1111 1111 = 255; 16 bits reach 65 535, the longest binary number you will be asked to convert.
Denary to binary: start at the largest place value. If it fits, write 1 and subtract; if not, write 0. Move right until you reach 1.
Try it: flip the bits
4. Converting hexadecimal
One hex digit stands for exactly four bits (a nibble), so 8 bits = 2 hex digits.
- Binary → hex: split into groups of 4 from the right, then convert each group. 1011 0110 → B 6 → B6.
- Hex → binary: write each digit as 4 bits, keeping leading zeros. 3F → 0011 1111.
- Hex → denary: first digit × 16, plus second digit. 3F → 3 × 16 + 15 = 63.
5. Uses of hexadecimal
Hex appears in HTML colour codes (#FF8800), MAC addresses, IPv6 addresses, error codes and memory dumps.
It is used because it is shorter and easier for people to read than binary, so fewer mistakes are made. It does not save storage: the computer still stores binary.
6. Binary addition and overflow
| Sum | Result | Carry |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 | 1 | 1 |
Add column by column from the right and always show the carries.
Overflow happens when the result needs more bits than the register holds. Two 8-bit numbers adding to more than 255 leave a 9th bit that cannot be stored, so the stored answer is wrong.
7. Logical binary shifts
- Left shift by n: every bit moves n places left; 0s fill the gaps on the right. Each place multiplies by 2.
- Right shift by n: bits move right; 0s fill on the left. Each place divides by 2 (whole-number division).
- Bits pushed off the end (the most or least significant bits) are lost, so a shift can give a wrong result.
Example: 0001 0110 (22) shifted left 2 → 0101 1000 (88).
8. Two’s complement
In 8-bit two’s complement the leftmost bit is worth −128, so the range is −128 to +127. A leading 1 means the number is negative.
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 |
To write −22: write +22 (0001 0110), flip every bit (1110 1001), then add 1 → 1110 1010. Check: −128 + 64 + 32 + 8 + 2 = −22.
9. Text: ASCII and Unicode
| Character set | Bits per character | Characters | Good for |
|---|---|---|---|
| ASCII | 7 (extended: 8) | 128 (256) | English text |
| Unicode | Up to 32 | Over a million | Every language and emojis |
Each character has a binary code from a character set. Unicode covers far more characters, but needs more bits per character, so text files are bigger.
10. Sound
A microphone produces an analogue wave. The computer measures (samples) its height at regular intervals and stores each sample in binary.
- Sample rate (sampling rate): samples taken per second, in hertz. Higher rate = more accurate recording, bigger file.
- Sample resolution (bit depth): bits used to store each sample. More bits = more accurate amplitude, bigger file.
Sound file size (bits) = sample rate × sample resolution × length in seconds.
11. Images
A bitmap image is a grid of pixels, and each pixel’s colour is stored as a binary number.
- Resolution: the number of pixels (width × height). More pixels = more detail, bigger file.
- Colour depth: bits per pixel. With n bits a pixel can be one of 2n colours (8 bits = 256 colours).
Image file size (bits) = width × height × colour depth.
12. Storage units and file size
The syllabus uses powers of 2 (1024), not 1000.
| Unit | Size |
|---|---|
| Nibble | 4 bits |
| Byte | 8 bits |
| Kibibyte (KiB) | 1024 bytes |
| Mebibyte (MiB) | 1024 KiB |
| Gibibyte (GiB) | 1024 MiB |
| Tebibyte (TiB) | 1024 GiB |
| Pebibyte (PiB) | 1024 TiB |
| Exbibyte (EiB) | 1024 PiB |
Bits ÷ 8 = bytes, then ÷ 1024 for each step up. Example: a 1024 × 512 image with a colour depth of 8 bits = 4 194 304 bits = 524 288 bytes = 512 KiB.
13. Compression
Compression makes files smaller, so they need less storage, transfer faster and use less bandwidth.
| Type | How it works | Result | Use it for |
|---|---|---|---|
| Lossy | Permanently removes data: lower resolution or colour depth, lower sample rate or resolution, sounds people cannot hear | Much smaller file, some quality lost, original cannot be restored | Photos, music, video |
| Lossless | No data lost, e.g. run-length encoding (RLE): AAAAABBB → 5A 3B | Smaller file, original rebuilt exactly | Text, program files |
14. Examiner tips
- Binary addition done in denary. Add in binary and show every carry, or you lose the working marks.
- Shifting the wrong way, or filling with 1s. Read “left” or “right” carefully, and fill with 0s.
- Two’s complement read as normal binary. A leading 1 means negative.
- Hex converted as one big number. For hex 14, convert the 1 and the 4 separately (0001 0100).
- Missing leading zeros. An 8-bit answer needs all 8 bits.
- Saying hex uses less memory. It doesn’t; it is just easier for people to read.
- Mixing up sample rate and sample resolution. Rate = per second; resolution = bits per sample.
- Image ideas in sound questions. Sample resolution has nothing to do with pixels.
- Naming a file type as a compression method. “Zip” or “JPEG” is not a method.
- Ignoring the context. Mention the scenario in your answer.
15. Practice questions
Practice: answer and check instantly
Q1 A sensor stores the denary value 77.
Show answer
0100 1101: 64 + 8 + 4 + 1 = 77, with a leading 0 to make 8 bits.
Show answer
0100 = 4 and 1101 = D, so 4D.
Show answer
A = 10, so 10 × 16 + 7 = 167.
Q2 Two 8-bit registers are added.
Show answer
1100 0001. In the exam, show every carry to get the working mark.
Show answer
0001 1011. The true answer is 283, which is more than 255, so the 9th bit is lost: this is an overflow error [2 more marks for explaining that].
Q3 The register holds 0011 0101.
Show answer
1101 0100. Every bit moves 2 places left and 0s fill on the right (53 × 4 = 212).
Show answer
0000 0110 = 6. The three right-most bits are lost, so 53 ÷ 8 gives 6, not 6.625.
More practice: Q4–Q8 (19 marks)
Five more exam-style questions on two’s complement, sound and image file sizes, Unicode and compression, each with a full mark guide, are included in Revision Hub Plus.
16. Topic test: predict your grade
Topic test: predict your grade
15 questions, about 10 minutes. Answer them all, then press Mark my test.
Frequently asked questions
How do you convert binary to denary?
Write the place values 128, 64, 32, 16, 8, 4, 2, 1 above the 8 bits and add the values wherever there is a 1. For example, 01101001 is 64 + 32 + 8 + 1 = 105.
Why is hexadecimal used in computing?
Hexadecimal is shorter and easier for humans to read than binary, so it is used for things like colour codes, MAC addresses and error codes. Each hex digit represents exactly 4 bits.
What is the difference between lossy and lossless compression?
Lossy compression permanently removes some data to make a much smaller file, as in JPEG and MP3. Lossless compression reduces file size without losing any data, so the original can be rebuilt exactly, as in run-length encoding.
How do you calculate the file size of an image?
Multiply the width in pixels by the height in pixels by the colour depth in bits. Divide by 8 to get bytes.