Calculator
Example Data Table
| Sample Input | Safe Encoded Output | Original Length | Encoded Length | Comment |
|---|---|---|---|---|
AAAAAAAAAAAA |
A:12 |
12 | 4 | Very strong compression because one symbol repeats. |
AAAAABBBBCCDAA |
A:5|B:4|C:2|D:1|A:2 |
14 | 19 | Mixed strings may expand because tokens need separators. |
AA BB |
A:2|\s:4|B:2 |
8 | 12 | Whitespace can be encoded safely and decoded later. |
Formula Used
1. Group adjacent identical symbols into runs.
2. Each run becomes escaped_symbol:count.
3. Join runs with | to create the safe encoded string.
4. Encoded length = total characters in the safe encoded string.
5. Compression ratio = encoded length ÷ original length.
6. Space saved = original length − encoded length.
7. Savings % = ((original length − encoded length) ÷ original length) × 100.
RLE works best when long repeated runs exist. Short or varied text often expands because counts, colons, and separators add overhead.
How to Use This Calculator
Step 1: Choose Encode for raw text or Decode for safe RLE input.
Step 2: Paste your text into the large input box.
Step 3: For encoding, apply optional trimming, case conversion, or whitespace removal.
Step 4: Click Calculate to generate results above the form.
Step 5: Review the encoded or decoded output, length metrics, run table, and Plotly graph.
Step 6: Use the download buttons to export the results as CSV or PDF.
Decode note: Use the safe pattern symbol:count|symbol:count. Enter \s for spaces, \n for line breaks, and escape | or : with a backslash.
FAQs
1. What does run length encoding do?
It replaces consecutive repeated symbols with a symbol and a count. For example, twelve A characters become one A token with a count of twelve.
2. Why can the encoded output become longer?
RLE adds counts and separators. If the source text has many short runs, the added notation can outweigh any compression benefit and expand the result.
3. What input format does decode mode expect?
Decode mode expects the safe pattern symbol:count|symbol:count. Spaces and control characters should be written with escapes like \s, \n, and \t.
4. Does the calculator handle spaces and line breaks?
Yes. Spaces and control characters are escaped in the safe output, so they can be decoded without ambiguity or losing structure.
5. What does compression ratio mean here?
It is encoded length divided by original length. A value below one means compression, while a value above one means the encoded version is larger.
6. Why is there a regenerated RLE value after decoding?
It verifies the decoded text by encoding it again. Matching results confirm that the safe token sequence is internally consistent.
7. When does RLE work best?
It works best on data with long repeated runs, such as simple bitmap rows, repetitive text blocks, or repeated placeholder characters.
8. What do the export buttons save?
CSV exports the summary metrics and run table. PDF exports the same result summary with the main inputs, outputs, and run details.