# A balancing act

By Michael Conterio. Posted

Originally published in Hello World 20: Systems and networks, Jan 2023. All information true at the time of original publishing.

A common problem students face is forgetting equations. Even when they have memorised equations, learners rarely understand what they mean and, therefore, struggle if what they want to figure out does not map exactly to the equation they learnt. In both cases, thinking about what each value in an equation represents can help — especially if you then use that to compare the units of each value. This article will provide some tips, using the example of calculating the colour depth of a bitmap image.

The colour depth of an image is the number of bits used to represent the colour of a single pixel from that image. In other words, it is the number of bits for one pixel, with a unit of ‘bits per pixel’. Bits per pixel simply means the number of bits in an image divided by the number of pixels in the image; you just have to work out which numbers of bits and pixels. Make sure they come from the same place — for example, the number of bits for an image and the number of pixels in that image.

### Equations with multiple terms

Knowing the equation and units for a quantity such as colour depth can help you use that quantity to calculate others. You can do this by combining different quantities you know the units of. By balancing the units, you can build up equations containing multiple terms and check that they look sensible. For example, imagine that you wanted to get the file size of a bitmap file and you already knew the colour depth. As colour depth is given by the number of bits divided by the number of pixels, you would need to multiply the colour depth by a number of pixels to get a file size in bits:

``file size [bits] = colour depth [bits/pixels] * number of pixels [pixels]``

The units here balance:

``bits = (bits/pixels) * pixels``

Divide both sides by pixels:

``bits/pixels = bits/pixels``

This now shows that the equation is balanced, as both sides are clearly equal.

Sometimes you might need to combine more things in a chain to get what you want. For example, imagine that you wanted to upload a bitmap image, and would like to know the time this would take. In this scenario, imagine that you also had the colour depth, but hadn’t calculated the size of the file. You’d start with an equation for upload time, in which the units balance. If you couldn’t remember this, you could work it out using the units, as you did for colour depth:

``upload time [seconds] = file size [bits] / upload speed [bits per second]``

The units in this equation look like this:

``seconds = bits/(bits/seconds) ``

Multiply both sides by (bits/seconds):

``(bits/seconds) * seconds = bits``

This is another way of saying:

``bits = bits ``

The units always have to balance!

As you don’t have the size of the file, but you have the colour depth and number of pixels, you can substitute the equation:

``file size [bits] = colour depth [bits/pixels] * number of pixels [pixels]``

... into the equation for upload time, to get an equation that doesn’t use the file size:

``upload time [seconds] = (colour depth [bits/pixels] * number of pixels) / upload speed [bits per second]``

You can check that the units match up:

``seconds = (bits/pixels) * pixels/(bits/seconds)``

``seconds = bits * (seconds/bits)``

``seconds = seconds``

Of course, in all of these cases, you or your students need to start by thinking about what each of the terms means. However, by combining quantities and units like this, you can exercise your knowledge and become happier with the mathematical side of computer science. What techniques do you use to help develop students’ understanding of computing terms and the mathematical side of computer science? We’d love to hear from you — tweet us at @HelloWorld_Edu ## Print

Free - UK only

If you’re a UK-based teacher, volunteer, librarian or something in between, we'll send each issue free to your door.

## Digital

Free

Just want to read the free PDF? Get each new issue delivered straight to your inbox. No fuss and no spam.