Overview
Introduction
Run-length encoding (RLE) is one of the oldest and simplest lossless compression techniques: instead of storing every repeated symbol individually, you store how many times it repeats.
This tool applies RLE to a binary string, representing it as a sequence of count-and-bit tokens that can be decoded back to the exact original string.
What Is Binary RLE Encoder?
A run-length encoder for binary strings, converting every run of consecutive identical bits into a single `<count>x<bit>` token.
It's the encoding half of a matched pair with Binary RLE Decoder, which reverses the process exactly.
How Binary RLE Encoder Works
The tool scans the binary string left to right, tracking the length of each run of consecutive identical digits.
Each time the digit changes (or the string ends), the run's length and digit are emitted as a `<count>x<bit>` token, and scanning continues from the next differing digit; all tokens are joined with spaces.
When To Use Binary RLE Encoder
Use it on binary data with long repeated runs, like sparse bitmaps, flag fields mostly set to one value, or simple black-and-white image rows, where RLE can meaningfully shrink the representation.
It's also a clear, hands-on way to see run-length encoding at work before implementing it in code.
Often used alongside Binary RLE Decoder and Binary Stream Comparer.
Features
Advantages
- Produces a compact, human-readable token format that's easy to inspect by eye.
- Losslessly reversible: Binary RLE Decoder reconstructs the exact original string from the encoded tokens.
- Handles runs of any length, including a run covering the entire input.
Limitations
- Not effective on data without long repeated runs; highly alternating bit patterns can encode to something longer than the original.
- The token format itself (spaces, 'x' separator, digit counts) is specific to this tool and its matching decoder, not a standardized interchange format.
Examples
Best Practices & Notes
Best Practices
- Check whether your data actually has long runs before relying on RLE; alternating data compresses poorly with this method.
- Use Binary RLE Decoder to verify a round trip reproduces your original string exactly.
Developer Notes
Implemented with a two-pointer scan (`i`, `j`) over the stripped digit string: `j` advances while digits match `digits[i]`, the run length `j - i` and digit `digits[i]` are pushed as a token, then `i` jumps to `j` to start the next run.
Binary RLE Encoder Use Cases
- Compressing sparse bitmaps or flag fields with long runs of the same value
- Encoding simple black-and-white image rows for a lightweight format
- Learning or demonstrating how run-length encoding works step by step
Common Mistakes
- Assuming RLE always shrinks the data; on highly alternating bit patterns the encoded form can be longer than the original.
- Mixing this tool's token format with a different RLE notation (like plain digit-run pairs without the 'x' separator) when decoding elsewhere.
Tips
- Feed the output straight into Binary RLE Decoder to confirm the round trip matches your original input.
- Look at the token count relative to the original bit length as a quick gauge of how compressible your data is.