next up previous contents
Next: Variable-Length Encoding Up: File Compression Previous: Motivation

Run-Length Encoding

A simple compression method uses the fact that, in certain sorts of files, we often get `runs' of repeated characters. A sequence such as:

aaaaabbbbbbbbbccccc
could be represented more concisely as:

5a 9b 5c

For binary files we can be even more concise:

11111111111000000011111111111111

could be represented simply as

11 8 14

as we can assume that we are alternating between 1s and 0s. Of course, numbers take up more space (bits) than 1s/0s to represent, but we can still get good savings if we have quite long runs of 1s or 0s (as may be common in some simple image formats, for example).

Run-length encoding isn't much good for text files, as repeated sequences aren't that common. However, it is quite useful for images. Many standard image-file formats are essentially compressed versions of the simple bitmap representation - run-length encoding is one compression method used.



Alison Cawsey
Fri Aug 28 16:25:58 BST 1998