Lesson 1 · How computers store data

🔢 Data Representation: Binary, Hex & File Sizes

A computer stores every number, letter, picture and sound as patterns of 0s and 1s. Knowing how to convert between systems lets you work out how much space a file needs.

🔟 Binary, denary and hexadecimal

Binary (base 2) uses place values 128, 64, 32, 16, 8, 4, 2, 1. Hexadecimal (base 16) uses 0–9 and A–F (A = 10 … F = 15). One hex digit stands for exactly four bits, so hex is a short way of writing long binary numbers.

binary 101101 = 32 + 8 + 4 + 1 = 45 denary 45 = 101101 hex 2F = 2 × 16 + 15 = 47 hex B7 = 11 × 16 + 7 = 183 binary 1111 1111 = hex FF = 255 binary addition: 0110 + 0101 = 1011 (6 + 5 = 11)
Shifts. A left shift of one place doubles a binary number; a right shift halves it. 00000101 (5) shifted left by 2 is 00010100 (20).

🖼️ See it

Binary place values128643216842100101101
This byte is 32 + 8 + 4 + 1 = 45 in denary and 2D in hexadecimal.
Hex digitsDenary101112131415HexABCDEF
Each hex digit stands for four bits, so FF is 1111 1111.

🔤 Text, images and sound

ASCII gives each character a code: A is 65, B is 66 and a is 97. An image is a grid of pixels, each stored with a colour depth (bits per pixel). Sound is sampled: the wave height is measured many times a second (the sample rate) with a number of bits per sample.

file size (bits) = width × height × colour depth 1000 × 500 pixels at 24 bits = 12 000 000 bits = 1 500 000 bytes sound (bits) = sample rate × bit depth × seconds 1000 Hz × 8 bits × 60 s = 480 000 bits = 60 000 bytes

📏 Units of storage

8 bits = 1 byte. In computing, 1 kilobyte (KB) = 1024 bytes, 1 megabyte (MB) = 1024 KB and 1 gigabyte (GB) = 1024 MB. Compression makes a file smaller: lossless keeps all the data (PNG, ZIP) and lossy removes some of it permanently (JPEG, MP3).

3 KB = 3 × 1024 = 3072 bytes 2 MB = 2 × 1024 = 2048 KB n bits give 2ⁿ values: 4 bits → 16 colours, 8 bits → 256
Common mistakes. Forgetting to divide the number of bits by 8 to get bytes. Using 1000 instead of 1024. Saying that lossy compression can be reversed.

🪜 Step by step: calculating an image file size

Bits = width × height × colour depth.

Problem: a 1000 × 800 image has 24 bits per pixel. Find the size in MB.

  1. Pixels. 1000 × 800 = 800 000
  2. Bits. 800 000 × 24 = 19 200 000
  3. Bytes. ÷ 8 = 2 400 000
  4. MB. ÷ 1 000 000 = 2.4 MB

Answer: 2.4 MB.

Common mistake: forgetting to divide by 8.
✏️ Quick check · 1 of 12
Hex

Why is hexadecimal used in computing?

Four bits per digit.
✏️ Quick check · 2 of 12
Compression

Which type of compression permanently removes some data?

You can not get it back.
✏️ Quick check · 3 of 12
Sampling

What happens to the sound quality and file size when the sample rate is increased?

More data is stored.
✏️ Quick check · 4 of 12
Colours

An image uses 4 bits for each pixel. How many different colours can it show?

2 to the power 4.
✍️ Type your answer · 5 of 12

A binary number is 101101.

Place values32116081412011
denary = ?

What is it in denary?

Enter an exact answer, without rounding.
Add the place values of the 1s.
✍️ Type your answer · 6 of 12

Add the binary numbers 0110 and 0101.

Binary add0110A0101B
A + B in denary = ?

What is the answer in denary?

Enter an exact answer, without rounding.
Convert and add.
✍️ Type your answer · 7 of 12

A hexadecimal number is 2F.

Hex places1621F
denary = ?

What is it in denary?

Enter an exact answer, without rounding.
F is 15.
✍️ Type your answer · 8 of 12

A hexadecimal number is B7.

Hex places16B17
denary = ?

What is it in denary?

Enter an exact answer, without rounding.
B is 11.
✍️ Type your answer · 9 of 12

The ASCII code of A is 65.

ASCII65ABC?D
code of D = ?

What is the ASCII code of D?

Enter an exact answer, without rounding.
Count on from A.
✍️ Type your answer · 10 of 12

A file is 3 KB, where 1 KB = 1024 bytes.

1 KB = 1024 bytes3 KB= ? bytes

How many bytes is that?

Enter an exact answer, without rounding.
bytes
Multiply by 1024.
✍️ Type your answer · 11 of 12

A picture is 1000 pixels wide and 500 high with 24 bits per pixel.

1000 × 500 pixels× 24 bits÷ 8= ? bytes

How big is the file, in bytes (8 bits = 1 byte)?

Enter an exact answer, without rounding.
bytes
Multiply, then divide by 8.
✍️ Type your answer · 12 of 12

A sound is sampled 1000 times a second with 8 bits per sample for 60 seconds.

1000 samples × 60 s8 bits = 1 byte each= ? bytes

What is the file size in bytes?

Enter an exact answer, without rounding.
bytes
Multiply, then divide by 8.
📝 Lesson quiz · 5 questions
0 / 5
Re-read the lesson, then give it another go.
Question 1 of 5

The binary number 1000 0000 is:

Question 2 of 5

One byte is:

Question 3 of 5

FF in hexadecimal is:

Question 4 of 5

Colour depth is:

Question 5 of 5

A PNG file uses: