Text to Binary: UTF-8 Bytes, Alignment and Decode Failures

Open Tool Text to Binary Converter

Typical uses

To see what a sentence looks like in memory, or to teach UTF-8's variable-length rules, converting to 8-bit groups of 0s and 1s is the clearest route. The English word Hi is 01001000 01101001, two bytes; a Chinese character takes three; a common smiley emoji takes four. The reverse works too: paste a 0101 string and read it back.

Steps

  1. Paste text or a 0101 string into the single input box; both directions share it and the tool detects the case.
  2. Click ⇅ to force a direction if detection guesses wrong, then click Convert.
  3. Enable space between bytes to split output per byte, so you can count them by eye; leave it off for one long run suited to code.
  4. Click Load example to see the expected format first.

Why the length must be a multiple of 8

Every byte is exactly 8 bits, so any valid binary string has a length divisible by 8. A mismatch usually comes from losing bits at one end when copying, or inserting spaces but dropping a single bit. To diagnose, strip all spaces, count the bits, then cut into 8-bit groups and match them against the source characters. Chinese text occupies 3 bytes per character, so its bit count is always a multiple of 24 — a quick sanity check.

Why decode produces question marks

Replacement characters mean the byte sequence is not valid UTF-8. A frequent cause is keeping only part of a multi-byte character, for example two of the three bytes for a Chinese glyph. Another is a non-UTF-8 source, such as GBK content already converted to bytes elsewhere. To tell the cases apart, decode to bytes and compare character counts: fewer characters than expected points to truncation.

⏫︎