RLE frequency/data pairs

Producing RLE Pairs from Data

To represent data using Run Length Encoding, you scan the data from left to right, counting each consecutive run of the same value. For each run you write a frequency/value pair: the count first, then the value. AQA uses the space-separated notation (e.g. 5 0) though you may also see the bracket form (5, 0) - both mean "the value 0 repeated 5 times".

For bitmap images, each row is encoded separately. Each pixel is stored as a binary value - typically 0 for one colour and 1 for another in a two-colour image. The pairs for each row are listed in sequence, reading left to right across that row.

Step-by-Step Method

  1. Start at the leftmost value in the row.
  2. Count how many consecutive positions hold that same value - this is the frequency.
  3. Write the frequency, then the value: e.g. 5 0.
  4. Move to the next different value and repeat until the row is complete.
  5. Check: the frequencies in all your pairs must add up to the total number of values in the original row.

Worked Examples

AQA-Style Bitmap Row

Encode the 16-pixel binary row: 0000011100000011

RunValueCountPair
00000055 0
111133 1
000000066 0
11122 1

RLE output: 5 0, 3 1, 6 0, 2 1  (also written (5,0)(3,1)(6,0)(2,1)).

Check: 5 + 3 + 6 + 2 = 16 ✓    8 stored values vs 16 original - a 50% reduction.

Symmetrical Pixel Pattern

Encode: 0011110000111100

RunValueCountPair
00022 0
1111144 1
0000044 0
1111144 1
00022 0

RLE output: 2 0, 4 1, 4 0, 4 1, 2 0  (also written (2,0)(4,1)(4,0)(4,1)(2,0)).

Check: 2 + 4 + 4 + 4 + 2 = 16 ✓    10 stored values vs 16 original.

Note: the symmetry of the pixel pattern is reflected in the symmetry of the RLE pairs (2,4,4,4,2).

Alternating Values - RLE Increases Size

Encode: 0101010101010101

RunValueCountPair
0011 0
1111 1
0011 0
............
16 runs of 1 → 16 pairs = 32 stored values

RLE output: 1 0, 1 1, 1 0, 1 1, 1 0, 1 1, 1 0, 1 1, 1 0, 1 1, 1 0, 1 1, 1 0, 1 1, 1 0, 1 1

32 stored values vs 16 original - the file has doubled in size.

This row has no repeated runs at all. Every value is different from its neighbour, so RLE produces a pair for every single pixel. Always check whether RLE actually reduces the data before applying it.

 Key Takeaways

  • Write RLE pairs as frequency value (e.g. 5 0) or equivalently (5, 0) - both forms appear in AQA materials.
  • Scan left to right: count each consecutive run of the same value, then write the count and the value as a pair.
  • Always verify your encoding: the frequencies in all pairs must sum to the original number of values in the row.
  • RLE saves space when runs are long. It increases file size when values alternate frequently, because each single-value run becomes its own pair.