In the previous course you found the size of an image or a sound in bits. Now you give that size in the unit the question asks for: bytes, kibibytes or mebibytes. You follow one clear chain of steps, always using 1024.
about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
The chain of steps
A file-size question gives you the facts and names the unit it wants. Answers must be in that unit. Every question follows the same chain.
A chain of four boxes from left to right: bits, bytes, KiB, MiB. The arrow from bits to bytes is labelled divide by 8, and the arrows from bytes to KiB and from KiB to MiB are each labelled divide by 1024. Under the bits box are the two rules: image = width times height times colour depth, and sound = sample rate times resolution times seconds.
Bits. Use the rule for the kind of file.
Bytes. Divide by 8.
KiB. Divide by 1024.
MiB. Divide by 1024 again, and so on up the ladder.
Stop as soon as you reach the unit the question asks for.
The rules for the bits come from the previous course.
A photo is 1024 pixels wide and 768 pixels high, with a colour depth of 24 bits. What is its size in MiB?
Bits.1024×768×24=18874368 bits.
Bytes.18874368÷8=2359296 bytes.
KiB.2359296÷1024=2304 KiB.
MiB.2304÷1024=2.25 MiB.
A short cut: 24 bits is 3 bytes, so each pixel takes 3 bytes. 1024×768×3=2359296 bytes, the same as before.
A sound in KiB and MiB
A recording is sampled 8192 times a second, with a sample resolution of 16 bits, for one minute. Give its size in KiB and in MiB.
Seconds. One minute is 60 seconds. Always change the time to seconds first.
Bits.8192×16×60=7864320 bits.
Bytes.7864320÷8=983040 bytes.
KiB.983040÷1024=960 KiB.
MiB.960÷1024=0.9375 MiB.
How many will fit?
Another kind of question asks how many files fit on a device. Put both sizes in the same unit, divide, and round down, because part of a file is no use.
A memory stick holds 1 GiB. Each song is 4 MiB. 1 GiB is 1024 MiB, and 1024÷4=256. So 256 songs fit.
Practise with new numbers
Try it in Python
The program has one function for the bits of an image and one for a sound, and a third that changes bits into any unit. It prints the two worked examples of this lesson.
Common mistakes
Stopping too soon. If the question asks for MiB, a size in bytes is not the answer.
Using 1000 instead of 1024.
Forgetting to change minutes to seconds in a sound question.
Rounding up the number of files. Only whole files fit, so round down.
Remember these
Bits, then divide by 8 for bytes, then by 1024 for each step up.