Text to binary and hex converter
Type in either box and the other one updates as you go. The converter turns text into UTF-8 bytes, so a letter like é takes two bytes and most emoji take four. It runs in your browser; nothing you enter is uploaded.
How text becomes binary
The converter first encodes the text as UTF-8, which turns each character into one to four bytes. Then it writes each byte as 8 binary
digits or 2 hex digits. "Hi" is two bytes, 72 and 105, so in binary it's 01001000 01101001 and in hex it's
48 69. Characters outside ASCII take more bytes:
| Character | Code point | UTF-8 in hex | UTF-8 in binary |
|---|---|---|---|
| H | U+0048 | 48 | 01001000 |
| é | U+00E9 | c3 a9 | 11000011 10101001 |
| € | U+20AC | e2 82 ac | 11100010 10000010 10101100 |
| 😀 | U+1F600 | f0 9f 98 80 | 11110000 10011111 10011000 10000000 |
Characters below U+0080 take one byte, the same byte as in ASCII. Most accented Latin letters, Greek, Cyrillic, Hebrew, and Arabic take two. The rest of the characters up to U+FFFF take three, including € and most Chinese, Japanese, and Korean text. Everything above U+FFFF takes four, as 😀 does. An emoji with a skin tone, or a family emoji, is several code points, so it can be well over four bytes. RFC 3629 defines the encoding.
Pasting binary or hex to decode
- You can separate the bytes with spaces, new lines, or commas, or run them together.
-
The converter reads a group with fewer than 8 binary digits as one byte with its leading zeros left out, so
1001000becomes01001000. It splits a longer group every 8 digits, so that group's length has to be a multiple of 8. - Hex works the same way with 2 digits per byte, in upper or lower case, and each byte may start with
0x.
When the bytes aren't valid UTF-8, the converter shows an error instead of guessing. The usual cause is text from another encoding: in
Latin-1, é is the single byte e9, and that byte on its own isn't valid UTF-8.
On the command line and in code
printf 'Hi' | xxd -b # binary, with byte offsets
printf 'Hi' | xxd -p # hex: 4869
echo 4869 | xxd -r -p # hex back to text: Hi In Python:
'Hi'.encode().hex(' ') # '48 69'
bytes.fromhex('48 69').decode() # 'Hi'
' '.join(f'{b:08b}' for b in 'Hi'.encode()) # '01001000 01101001'
bytes(int(b, 2) for b in s.split()).decode() # binary back to text
In JavaScript, new TextEncoder().encode('Hi') gives the bytes as a Uint8Array, and
byte.toString(2).padStart(8, '0') writes one of them in binary.
Questions
Why does each byte take 8 binary digits?
A byte is 8 bits, and the leading zeros are kept so every byte has the same width. "H" is 72, which is 1001000 in seven
digits and 01001000 as a byte.
Is this the same as ASCII to binary?
Yes, for text made only of ASCII characters: UTF-8 gives them the same single bytes. Other characters have no ASCII code, so a converter
has to choose an encoding. This one uses UTF-8, the only encoding the browser's TextEncoder supports.
Should I use binary or hex?
Use hex for anything you'll read or compare. Each byte is 2 characters instead of 8, and tools such as xxd, Wireshark, and
browser developer tools show bytes in hex. Pick binary when you want to see individual bits, such as the 110 and
10 markers at the start of the UTF-8 bytes in the table above.