Decoding 8-Bit Binary Streams Into Valid UTF-8 Text
In ASCII, every printable character occupies a single 7-bit code point stored inside an 8-bit byte whose most significant bit (MSB) is 0 (00000000 to 01111111). Once the MSB is 1, UTF-8 uses leading bit prefixes (110xxxxx for 2 bytes, 1110xxxx for 3 bytes, 11110xxx for 4 bytes) followed by continuation bytes beginning with 10xxxxxx.
Naively converting each 8-bit octet with String.fromCharCode() treats UTF-8 bytes as ISO-8859-1 Latin-1, turning a 3-byte euro sign (0xE2 0x82 0xAC) into three garbled characters. Collecting the parsed octets into a Uint8Array and passing it through TextDecoder('utf-8') guarantees faithful Unicode reconstruction.
- Character EncodingRFC 3629 UTF-8 decoding via TextDecoder (strictly handles 1- to 4-byte Unicode sequences).
- Bit AlignmentSplits on whitespace/delimiters or chunks raw 0/1 streams into 8-bit octets (left-padding optional).
- Control CharactersDisplays non-printable ASCII codes (0x00–0x1F, 0x7F) with explicit mnemonic labels in byte breakdown.
Why does my binary input need a multiple of 8 bits?
UTF-8 and modern ASCII strings are byte-aligned to 8-bit octets. If a 7-bit ASCII byte omits its leading zero (such as 1000001 for 'A'), separating groups with spaces lets the decoder zero-pad each token to 8 bits.
Can this tool decode UTF-8 emojis and non-Latin scripts from binary?
Yes. Because it reconstructs a Uint8Array and decodes with UTF-8, 2-, 3-, and 4-byte sequences such as accented letters, CJK ideographs, and emojis decode cleanly.
What happens when an invalid UTF-8 byte sequence appears?
Invalid continuation bytes or truncated multi-byte sequences render as the Unicode replacement character (U+FFFD) and are flagged in the byte-level inspection view.