Your binary converter is lying about emoji (and accents too)
Type "Hi" into any binary converter and you get this: 01001000 01101001 Correct. Every letter is a number, binary is that number written with only two digits, and H is 72, which is 01001000 in eight bits. Simple
Type "Hi" into any binary converter and you get this:
01001000 01101001
Correct. Every letter is a number, binary is that number written with only two digits, and H is 72, which is 01001000 in eight bits. Simple, satisfying, and the reason every beginner tutorial starts here.
Now type "cafΓ©".
A lot of converters will give you four groups, one per character, and one of them will be wrong. Some will give you a question mark. Some will silently drop the accent and hand you back "cafe" as if nothing happened. The worst ones will give you a confident-looking answer that decodes to something else entirely.
The problem is not binary. The problem is what the converter thinks a character is.
A character is not always one byte
ASCII, the 1960s encoding most tutorials still teach, covers 128 characters: English letters, digits, punctuation. One character, one byte, seven bits plus a leading zero. "Hi" is two characters, two bytes, done.
But the text you actually type is not ASCII. It is UTF-8, the encoding the whole web runs on, and UTF-8 is variable-width: one character can be one, two, three, or four bytes.
-
His one byte:01001000 -
Γ©is two bytes:11000011 10101001 -
β¬is three bytes:11100010 10000010 10101100 -
πis four bytes:11110000 10011111 10010001 10001011
An ASCII-only converter has no way to write Γ©. It sees a character outside its 128, and whatever it does next is a guess: drop it, replace it with ?, or encode only its first half. The output looks like binary, it even looks right, and it is wrong.
How to tell if a converter is lying
The test takes five seconds. Encode "cafΓ©" and count the groups:
-
5 groups (
01100011 01100001 01100110 11000011 10101001): correct. Four letters, five bytes, becauseΓ©takes two. - 4 groups: it treated every character as one byte. The accent is gone or mangled.
- A question mark anywhere: it gave up and hoped you would not notice.
Then decode it back. A correct converter returns exactly what you typed. If "cafΓ©" comes back as "caf?" or "cafe", the converter is lossy, and lossy is the one thing a converter must never be.
The same trap in code
If you have ever written a binary encoder in JavaScript, you have probably written the buggy version:
// Buggy: treats every character as one byte
function toBinary(text) {
return [...text].map(c => c.charCodeAt(0).toString(2).padStart(8, '0')).join(' ');
}
charCodeAt returns the UTF-16 code unit, not the UTF-8 bytes. For Γ© (U+00E9, code 233) it produces 11101001, a single byte that is not valid UTF-8 on its own. Decode that and you get garbage, or an error, depending on the decoder's mood.
The correct version encodes to UTF-8 bytes first:
// Correct: real UTF-8 bytes, accents and emoji included
function toBinary(text) {
const bytes = new TextEncoder().encode(text);
return [...bytes].map(b => b.toString(2).padStart(8, '0')).join(' ');
}
function fromBinary(binary) {
const groups = binary.trim().split(/\s+/);
const bytes = new Uint8Array(groups.map(g => parseInt(g, 2)));
return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
}
TextEncoder does the real work: it turns "cafΓ©" into five bytes, "π" into four, and the round trip is exact. The { fatal: true } on the decoder matters too: without it, invalid bytes silently become the replacement character and you never learn your input was broken.
The 7-bit mode is real, just not for real text
You will also see converters offering 7-bit ASCII mode, one group of seven bits per character. That is the textbook form, and it is legitimate for exactly one job: homework and exams that ask for it. H becomes 1001000 instead of 01001000, and the whole string is shorter.
The rule is simple: 7-bit mode only works for the 128 ASCII characters. The moment an accent, a Γ±, or an emoji appears, the mode must refuse, loudly, with a named error. A converter that quietly encodes Γ© as seven bits has invented a byte that does not exist.
Why errors should point, not shrug
Binary input fails in exactly three ways, and a good converter names which one and where:
-
A digit that is not 0 or 1. Binary has two digits. A
2at position 8 is a typo, and the error should say "position 8" instead of "invalid input". -
A short final group. Seven bits in 8-bit mode usually means a missing leading zero:
1001000should be01001000. Count the last group first. -
Bytes that are not valid UTF-8.
11111111is a byte, but it is not the start of any real character. The decoder should say so instead of inventing a replacement character.
Vague errors waste the most time precisely because the fix is always trivial once you can see it.
One converter that gets this right
I built one that does exactly what this article describes: Binary to Text Converter. Text to binary and binary to text in both directions, auto-detect so you never pick a mode first, UTF-8 by default with a 7-bit ASCII mode that refuses non-ASCII input honestly, spaced, comma, or continuous groups, and a byte table under the converter showing every character as binary, hex, and decimal. Errors name their exact position, and nothing you type leaves your browser.
If you are moving bytes into text for transport instead, the Base64 Encoder on the same site is the right tool: same UTF-8 honesty, plus file mode and the URL-safe alphabet.
The one-line takeaway
A character is not a byte. Test any binary converter with "cafΓ©": five groups means it understands UTF-8, four groups means it is guessing, and a question mark means it gave up. Pick the one that passes the cafΓ© test.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.