Text to Binary Converter: how it works and how to build one
Convert text to binary, hex, octal or decimal bytes and back. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Text is encoded as UTF-8 first, so emoji and non-Latin letters work. Each byte is shown in binary (8 digits), hex, octal or decimal. Decoding accepts bytes separated by spaces or commas, or one long string of binary.
When to use it
- Learning about encodings
- Debugging byte-level data
- Puzzles
How to use it
- Pick binary, hex, octal or decimal.
- Choose Text → Code or Code → Text.
- Copy the result.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/text-to-binary
How it works
Computers store text as bytes. TextEncoder turns a string into its UTF-8 bytes, and each byte (0–255) can be written in binary (8 digits), hex (2 digits), octal or decimal.
Decoding reads each group back into a byte and uses TextDecoder to rebuild the text, which handles multi-byte characters like ✓.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
binary.ts (ts)
export const textToBinary = (s: string) =>
[...new TextEncoder().encode(s)].map((b) => b.toString(2).padStart(8, "0")).join(" ");
export const binaryToText = (s: string) =>
new TextDecoder().decode(new Uint8Array(s.trim().split(/\s+/).map((b) => parseInt(b, 2))));
Make it production-ready
- Accept one long string of bits by splitting every 8 characters.
- Add hex and decimal modes with the same idea.
Questions
Why does ✓ give three bytes?
UTF-8 uses 1 to 4 bytes per character. ASCII letters use one byte, most symbols and Indian scripts use three.
Free, runs in your browser, nothing is uploaded.