How to convert text to hex
Computers store text as bytes, and hex is a short way to write a byte: two digits from 00 to ff. To convert text to hex, the tool turns each character into bytes using a character set, then writes every byte as two hex digits. The word Hello becomes:
48 65 6C 6C 6FEach letter is one byte, so the status line reads 5 characters, 5 bytes, UTF-8. A line that holds more than plain English letters shows the difference. The sample, Hello, world! on one line and Café €5 followed by an emoji on the next, starts with the bytes 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0A, where 0A is the line break. The letter é and the symbols after it use more.
Why one character can be several bytes
UTF-8 uses one byte for the first 128 characters, which covers English letters, digits and common punctuation. Other characters take two, three or four bytes. For a text up to 60 characters, the Bytes panel lists them. For Aé followed by an emoji it shows:
A U+0041 41 · 1 byte
é U+00E9 C3 A9 · 2 bytes
😀 U+1F600 F0 9F 98 80 · 4 bytesThe code point, written U+ and a hex number, is the character's identity in Unicode. The bytes are how a character set writes it down. Other sets write the same character differently. In UTF-16 little-endian the same text starts 41 00 and uses two bytes for é and four for the emoji. Switch the character set and the panel updates.
Text to hex in the format your code needs
A column of plain hex is fine for reading. For code, the Format menu writes the same two bytes of the word Hi in the shapes programmers use:
- Spaced: 48 69
- Continuous: 4869
- 0x list: 0x48, 0x69, for a C or JavaScript array
- \x string: "\x48\x69", for a C or Python string
- Percent: %48%69, as in a URL
- SQL literal: 0x4869, for MySQL and SQL Server binary values
- SQL literal: X'4869', for MySQL and SQLite
Bytes per line breaks long output into rows of 8, 16 or 32. In the 0x list, each row ends with a comma, so you can paste it between braces. In the \x string every row is wrapped in quotes. Percent codes and SQL literals stay on one line. Uppercase letters is on by default. Turn it off for the lowercase style that Python and many languages print.
Text to hex with ASCII, Latin-1 and UTF-16
ASCII holds 128 characters. If your text has anything else, the tool stops and says which character and where, for example ASCII cannot hold "é" (U+00E9) at line 1, column 2. It does not replace the character with a question mark, because that would silently change your data. Latin-1 / Windows-1252 writes one byte for each character it knows, including é and the euro sign, and gives the same error for the rest. UTF-8 and UTF-16 hold every character.
Hex is only another way to write bytes. It is not encryption, and anyone can turn it back into text with Hex to Text.
Line breaks in the output
A line break is the byte 0A on Linux and macOS, and the two bytes 0D 0A on Windows. The input box keeps line breaks as 0A. If the hex has to match a Windows file or a protocol that uses CRLF, set Line breaks to Windows. The notes say when that was applied.
Text to hex in Python, JavaScript and on the command line
In Python, encode the string and call hex:
print("Hello".encode("utf-8").hex(" "))In JavaScript, TextEncoder gives the bytes, and the rest formats them:
Array.from(new TextEncoder().encode("Hello"), (b) => b.toString(16).padStart(2, "0")).join(" ")On the command line, xxd -p prints plain hex:
printf 'Hello' | xxd -pIn Excel, DEC2HEX(CODE(A1)) gives the hex of one character. For whole strings, paste them here. For a different encoding of the same bytes, Base64 Encode and URL Encode write them as Base64 and percent codes, and File to Base64 does it for a file.
Limits
- The tool encodes text. It does not read files, so use File to Base64 to turn a file into text.
- Characters that a chosen character set cannot hold stop the conversion with an error.
- An unpaired surrogate, which is not valid Unicode, is written by UTF-8 as EF BF BD and the notes say so.
- Latin-1 here means Windows-1252, as in browsers. It differs from strict ISO-8859-1 only for the bytes 80 to 9f.
- Very large input is limited to 2,000,000 characters.
Your text is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.