Overview
Introduction
Swapping out a known bit pattern everywhere it appears, correcting a mis-set flag sequence, masking a repeated field, or normalizing a pattern, is a common step when hand-editing binary data.
This tool performs that find-and-replace across an entire binary string in one pass, with the replacement allowed to be empty when you just want matches deleted.
What Is Binary Replacer?
A find-and-replace tool for binary strings that locates every non-overlapping occurrence of one bit sub-sequence and substitutes another in its place.
Both the sequence to find and its replacement are validated as binary, except the replacement may be left empty to delete matches outright.
How Binary Replacer Works
The input, find sequence, and replacement are each stripped of grouping characters and validated (the replacement is allowed to be empty).
The input is split on every occurrence of the find sequence, which naturally produces one segment per gap between matches, and those segments are rejoined using the replacement sequence, equivalent to a global string replace.
When To Use Binary Replacer
Use it to correct a mis-set flag pattern that repeats throughout a binary string, or to mask/redact a repeated sensitive field.
It's also useful for quickly testing how a byte pattern substitution would change a sample bitstream before writing that logic in code.
Often used alongside Binary Slicer and Binary Joiner.
Features
Advantages
- Reports exactly how many replacements were made, so you can confirm the expected number of matches were found.
- Supports deleting a sequence outright by leaving the replacement empty, rather than requiring a separate delete tool.
- Validates both the find and replace sequences as binary up front, catching typos before they corrupt the output.
Limitations
- Matches are literal and non-overlapping; it has no regex or wildcard support for fuzzy or overlapping pattern matching.
- Because matching is non-overlapping, a find sequence containing a repeated internal pattern may match fewer times than a naive overlapping search would find.
Examples
Best Practices & Notes
Best Practices
- Check the reported occurrence count after replacing to confirm the expected number of matches were found.
- Use Binary Slicer first to isolate a region if you only want replacements applied within part of a longer string.
Developer Notes
Implemented as `bits.split(findBits).join(replaceBits)`, which is functionally equivalent to a global, non-overlapping string replace without relying on regex escaping.
Binary Replacer Use Cases
- Correcting a mis-set flag pattern that repeats throughout a binary string
- Masking or redacting a repeated sensitive field by replacing it with zeros
- Testing how a byte-pattern substitution would change a sample bitstream
Common Mistakes
- Expecting overlapping occurrences of the find sequence to all be matched; matching is non-overlapping and consumes each match before continuing.
- Leaving the find field's stray spaces in place and being confused when nothing matches; grouping characters are stripped, but the underlying digits still need to appear exactly.
Tips
- Leave the replacement empty to delete every occurrence of a sequence instead of substituting something else.
- Use Binary RLE Encoder first if you're trying to find every run of the same bit rather than a specific fixed sequence.