Overview
Introduction
Once binary data has been run-length encoded into compact count-and-bit tokens, you eventually need a way to reconstruct the original bitstream.
This tool does exactly that: it reads `<count>x<bit>` tokens and expands each one back into its repeated bits, exactly reversing what Binary RLE Encoder does.
What Is Binary RLE Decoder?
A run-length decoder that expands `<count>x<bit>` tokens back into a full binary string.
It's the decoding half of a matched pair with Binary RLE Encoder, sharing the identical token notation so the two tools round-trip cleanly.
How Binary RLE Decoder Works
The input is split on whitespace into individual tokens, and each is matched against the pattern `<digits>x<0 or 1>`.
For every valid token, the bit is repeated `count` times using `String.prototype.repeat()`, and the results are concatenated in order to rebuild the original string.
When To Use Binary RLE Decoder
Use it to reverse output produced by Binary RLE Encoder, or any data following the same `<count>x<bit>` token convention.
It's also a quick way to hand-construct a binary string with specific long runs without typing every repeated digit yourself.
Often used alongside Binary RLE Encoder and Binary Stream Comparer.
Features
Advantages
- Exactly reverses Binary RLE Encoder's output, guaranteeing a lossless round trip.
- Validates every token's format and reports the specific token that's malformed, rather than failing on the whole input silently.
- Doubles as a convenient way to generate a binary string with specific runs by hand-writing tokens.
Limitations
- Only understands this tool's specific `<count>x<bit>` space-separated notation; it won't parse other RLE formats (like comma-separated pairs or byte-oriented RLE) without reformatting first.
- A very large count in a single token expands to a proportionally long string, extremely large counts could produce an impractically long output.
Examples
Best Practices & Notes
Best Practices
- Round-trip your data through Binary RLE Encoder and back through this tool to confirm the encoding is lossless for your specific input.
- Write tokens with explicit counts (like "1x1" for a lone bit) rather than omitting the count, since the format always requires one.
Developer Notes
Implemented with a regular expression `/^([0-9]+)x([01])$/` to validate and parse each whitespace-separated token, then `match[2].repeat(Number(match[1]))` to expand it, concatenating all expansions in order.
Binary RLE Decoder Use Cases
- Reversing output produced by Binary RLE Encoder back to a raw binary string
- Hand-constructing a binary string with specific long runs without typing every digit
- Verifying that an RLE-compressed representation decodes back to the expected original data
Common Mistakes
- Pasting tokens from a different RLE notation (e.g. bit-first like "1x3") and getting a parse error, since this decoder expects count-first, `<count>x<bit>`.
- Forgetting spaces between tokens, which causes the whole input to fail as a single unmatched token.
Tips
- Use Binary RLE Encoder first if you're not sure your tokens are formatted correctly, then compare its output to your input.
- A token count of 1 is valid and simply represents a lone bit, e.g. "1x1" decodes to just "1".