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
- Start at the leftmost value in the row.
- Count how many consecutive positions hold that same value - this is the frequency.
- Write the frequency, then the value: e.g. 5 0.
- Move to the next different value and repeat until the row is complete.
- 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
| Run | Value | Count | Pair |
|---|---|---|---|
| 00000 | 0 | 5 | 5 0 |
| 111 | 1 | 3 | 3 1 |
| 000000 | 0 | 6 | 6 0 |
| 11 | 1 | 2 | 2 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
| Run | Value | Count | Pair |
|---|---|---|---|
| 00 | 0 | 2 | 2 0 |
| 1111 | 1 | 4 | 4 1 |
| 0000 | 0 | 4 | 4 0 |
| 1111 | 1 | 4 | 4 1 |
| 00 | 0 | 2 | 2 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
| Run | Value | Count | Pair |
|---|---|---|---|
| 0 | 0 | 1 | 1 0 |
| 1 | 1 | 1 | 1 1 |
| 0 | 0 | 1 | 1 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.