Binary and data representation - EdexcelThe need for data compression

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

The need for data compression

Modern computer processing often generates files of very large sizes. For example, audio files often run to , while high definition video can be in size. Such files require lots of storage space, and, because of their size, are difficult to transmit. These problems can be overcome by using .

There are two types of compression that can be applied to files:

  • compression
  • compression

An explanation of lossy and lossless compression

Lossy compression

With lossy compression, some is removed and discarded, thereby reducing the overall amount of data and the size of the file.

An image can be compressed by reducing its . This reduces the range of colours that the image contains. In practice, this results in an averaging of shades of colours. For example, a very light shade of green could be averaged with a not so light shade - the very light shade might be discarded, and the pixels affected by it re-coloured with the darker shade.

Various lossy standards exist:

  • the JPEG file format works on this principle, which is why JPEG files tend to be smaller in size
  • the MPEG file format compresses audio and video, making it more suitable for streaming media
  • is a lossy format for audio, including music
A high resolution image next to a compressed version of the same image

Similarly, an audio file can be compressed by reducing the of the samples.

Lossless compression

There are some files that programmers do not want to lose data from. For example:

  • text files
  • spreadsheets
  • financial records
  • emails

With lossless compression, files are reduced in size without the loss of data. However, lossless compression does not usually achieve the same file size reduction as lossy compression.

Various lossless standards exist, eg:

  • allows lossless compression of text documents
  • is a lossless image file format

One method of lossless compression is run length encoding (RLE). RLE looks at the data in a file for consecutive runs of the same data. These runs are stored as one item of data, instead of many.

Consider this row in a bitmap image:

Bitmap image showing ten data values with two characters each

The data for this is 00 00 00 11 11 11 11 00 00 00, which is ten data values of two characters each, giving 20 characters in total. RLE looks for the runs of each data, and records what the data is and how many times in succession it occurs. These values are stored instead of the original data.

For example:

00000011111111000000 - 20 characters - becomes

608160 - 6 characters