Checking whether a file fits in the available storage

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Checking whether a file fits in the available storage

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A 600 MiB video is to be saved on a 2 GiB drive. What must you do before comparing the two sizes?
A Convert both to the same unit
B Compare 600 and 2 directly
2. Which condition shows that a file fits in the free space?
A file size > free space
B file size <= free space
3. A 3 GiB file and a drive with 2048 MiB free. Does the file fit?
A No, 3 GiB = 3072 MiB, which is more than 2048 MiB
B Yes, because 3 is smaller than 2048
4. A sound file is 512 KiB and the free space is 1 MiB. Does the file fit?
A No, because 1 is smaller than 512
B Yes, 1 MiB = 1024 KiB and 512 KiB is less than 1024 KiB
5. A 2 GiB file is saved onto a drive with exactly 2048 MiB free. Does it fit?
A Yes, the sizes are equal so it just fits
B No, the file must be strictly smaller

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1file_bytes <= free_bytes AThe file fits because both sizes are in bytes and the file is not bigger than the free space
2files = capacity // file_size BThe numbers are in different units: 5 is in MiB but 4096 is in KiB. Comparing them directly is wrong.
3Convert a 2 GiB drive into MiB before comparing it with a 1500 MiB sound file CWorks out how many whole files fit in the storage, after both sizes are in the same unit
4Find how many 4 MiB images fit on a 64 MiB card D64 / 4 = 16 images
55 MiB file on 4096 KiB: 5 <= 4096, so it fits EThe file size is in GiB and the drive is in MiB, so comparing 3 with 2048 is not a fair check.
6File 3 GiB, drive 2048 MiB: 3 <= 2048, so it fits F2 * 1024 = 2048 MiB, so 1500 <= 2048

Definitions

file size <= capacity

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF fileSize __ freeSpace THEN
2.
freeBytes ← freeMiB * 1024 * ____
3.
freeMiB ← 100 fileMiB ← 8 numFiles ← freeMiB ___ fileMiB
4.
IF fileMiB <= freeMiB ____
5.
imageMiB ← 350 driveMiB ← 2048 IF imageMiB <= ________ THEN

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A fileMiB ← 300
B driveGiB ← 2
C driveMiB ← driveGiB * 1000
D IF fileMiB <= driveMiB THEN
E OUTPUT "Fits"
F ENDIF
Question 2
A fileMiB ← 600
B freeMiB ← 650
C IF fileMiB > freeMiB THEN
D OUTPUT "Fits"
E ENDIF
Question 3
A capGiB ← 1
B capMiB ← capGiB / 1024
C fileMiB ← 4
D count ← capMiB DIV fileMiB
E OUTPUT count
Question 4
A fileBytes ← 2 * 1024
B freeBytes ← 3000000
C IF fileBytes <= freeBytes THEN
D OUTPUT "Fits"
E ENDIF
Question 5
A imageBytes ← 6291456
B imageKiB ← imageBytes * 1024
C driveKiB ← 5000
D fits ← imageKiB <= driveKiB
E OUTPUT fits

Answer Key

Checking whether a file fits in the available storage
Section A: Quick Questions
Q1
A — Convert both to the same unit
Q2
B — file size <= free space
Q3
A — No, 3 GiB = 3072 MiB, which is more than 2048 MiB
Q4
B — Yes, 1 MiB = 1024 KiB and 512 KiB is less than 1024 KiB
Q5
A — Yes, the sizes are equal so it just fits
Section B: Match the Pairs
Q1
file_bytes <= free_bytes → The file fits because both sizes are in bytes and the file is not bigger than the free space
Q2
files = capacity // file_size → Works out how many whole files fit in the storage, after both sizes are in the same unit
Q3
Convert a 2 GiB drive into MiB before comparing it with a 1500 MiB sound file → 2 * 1024 = 2048 MiB, so 1500 <= 2048
Q4
Find how many 4 MiB images fit on a 64 MiB card → 64 / 4 = 16 images
Q5
5 MiB file on 4096 KiB: 5 <= 4096, so it fits → The numbers are in different units: 5 is in MiB but 4096 is in KiB. Comparing them directly is wrong.
Q6
File 3 GiB, drive 2048 MiB: 3 <= 2048, so it fits → The file size is in GiB and the drive is in MiB, so comparing 3 with 2048 is not a fair check.
Section C: Definitions
Q1
file size <= capacity — A file fits if its size is less than or equal to the free space. First convert both to the same unit, such as bytes or MiB, then compare the two numbers.
Section D: Fill in the Blanks
Q1
IF fileSize <= freeSpace THEN
Q2
freeBytes ← freeMiB * 1024 * 1024
Q3
freeMiB ← 100 fileMiB ← 8 numFiles ← freeMiB DIV fileMiB
Q4
IF fileMiB <= freeMiB THEN
Q5
imageMiB ← 350 driveMiB ← 2048 IF imageMiB <= driveMiB THEN
Section E: Spot the Error
Q1
C — To convert GiB to MiB you multiply by 1024, not 1000. It should be driveMiB ← driveGiB * 1024, so both sizes are in MiB before comparing.
Q2
C — A file fits when its size is less than or equal to the free space. The test should be fileMiB <= freeMiB, not >.
Q3
B — Going from GiB to the smaller unit MiB means multiplying by 1024, not dividing. It should be capMiB ← capGiB * 1024.
Q4
A — 2 MiB in bytes needs two multiplications by 1024 (MiB to KiB to bytes). It should be fileBytes ← 2 * 1024 * 1024.
Q5
B — Converting bytes to the larger unit KiB means dividing by 1024, not multiplying. It should be imageKiB ← imageBytes / 1024.