Binary and data representation - EdexcelCalculating file sizes

All data in a computer is represented in binary, whether it is numbers, text, images or sound. The computer software processes the data according to its content.

Part ofComputer SciencePrinciples of computer science

Calculating file sizes

Understanding how to calculate file sizes helps to estimate how much storage is needed to save files such as images, music and documents.

Text documents

A plain text document is a type of file that contains only letters, numbers, symbols and characters. It can be created in any word-processing software. Each character (letter, number, symbol or space) takes up 1 byte in extended .

ASCII uses 7 bits per character, giving a character set of 128 characters. Extended ASCII uses 8 bits (1 byte) per character, giving a character set of 256 characters.

Example

The file size calculation = number of characters x bytes per character.

Therefore, a text file with 150 characters using extended ASCII: 150 x 1 = 150 bytes.

Bitmap images

A bitmap image is made up of a grid of pixels, with each pixel being a specific colour.

The file size depends on the width and height of the image in pixels, and the colour depth (number of bits per pixel.)

Example

To calculate the file size of an image with a width of 800 pixels and a height of 600 pixels with 24-bit colour:

File size = width x height x colour depth

So 800 x 600 x 24 = 11,520,000 bits

To work out the file size in bytes, divide the answer by 8, as there are 8 bits in a byte.

Therefore 11,520,000 / 8 = 1,444,000 bytes or 1.44 MB.

Sound files

Sound files contain digital audio information such as music or speech. File size depends on the (samples per second), sample resolution (bits per sample), length (in seconds) and the number of channels (1 for mono, 2 for stereo.)

File size = sample rate x sample resolution x time x number of channels.

Example

A 10-second stereo clip sampled at 44,100 Hz using 16-bit resolution:

10 x 2 x 44,100 x 16 = 14,112,000 bits

To work out the file size in bytes, divide the answer by 8, as there are 8 bits in a byte.

Therefore, 14,112,000 / 8 = 1,764,000 bytes or 1.76 MB.

Storage capacity

Once the file size is known, a calculation can be made as to how many files will fit on a storage device.

Number of files = storage capacity / file size

Example

A USB memory stick has 8 GB (8 x 1,000 x 1,000 x 1,000 = 8,000,000,000 bytes)

If each photo is 2 MB (2 x 1,000 x 1,000 = 2,000,000 bytes)

Therefore, 8,000,000,000 / 2,000,000 = 4,000 photos.