What this tool does
Run-length encoding (RLE) is one of the oldest and simplest lossless compression methods. It replaces a “run” of identical consecutive characters with a single count followed by the character. This tool both encodes text into RLE form and decodes RLE back to the original.
How it works
Encoding scans the string left to right, counting how many times the current character repeats consecutively. When the character changes (or the string ends), it writes the count followed by that character, then resets the counter. Every run — even a run of length one — is written with an explicit count, so AAABBC becomes 3A2B1C. This explicit-count rule keeps decoding unambiguous.
Decoding reads a sequence of count-then-character pairs. It accumulates all leading digits into a number, then repeats the next character that many times. So 12X expands to twelve Xs, and 3A2B1C expands back to AAABBC.
Example
Input: WWWWWWWWWWWWBWWWWWWWWWWWWBBB
Encoded: 12W1B12W3B
That run of 27 characters compresses to 10 — a clear win because the data is highly repetitive.
Notes
- RLE shrinks data only when runs are long; on varied text it can grow the output, since each isolated character costs an extra count digit.
- The tool counts by Unicode code point, so emoji and accented characters are treated as single symbols.
- For correct round-tripping, keep the count-character pairing intact when editing encoded text by hand.