Text to hex: what the bytes are
Text is stored as bytes, and a byte (8 bits) is written with two hexadecimal digits from 00 to FF. Converting text to hex means encoding the string into bytes first and then writing each byte in base 16. The result depends on the encoding: "A" is 41 in every common one, but an accented letter is one, two or more bytes depending on the encoding you pick. This page opens the converter in the text to hex direction, with a sample loaded.
Worked example: Hello
The same five bytes in the six output formats of the tool:
| Format | Result |
|---|---|
| Spaced | 48 65 6c 6c 6f |
| Compact | 48656c6c6f |
| 0x prefix | 0x48 0x65 0x6c 0x6c 0x6f |
| Escaped (\x) | \x48\x65\x6c\x6c\x6f |
| C array | 0x48, 0x65, 0x6c, 0x6c, 0x6f |
| Colons | 48:65:6c:6c:6f |
The encoding changes the bytes
"Olá" in four encodings. Only the accented letter changes; note the byte counts:
| Encoding | Bytes in hex | Count |
|---|---|---|
| UTF-8 | 4f 6c c3 a1 | 4 |
| UTF-16LE | 4f 00 6c 00 e1 00 | 6 |
| UTF-16BE | 00 4f 00 6c 00 e1 | 6 |
| ISO-8859-1 | 4f 6c e1 | 3 |
ISO 8859-1 and ASCII refuse what they cannot hold instead of writing a "?": a euro sign or an emoji gives an error that names the character and its code point.
Quick reference: letters and digits
| Character | Hex |
|---|---|
| A | 41 |
| B | 42 |
| C | 43 |
| a | 61 |
| b | 62 |
| c | 63 |
| 0 | 30 |
| 9 | 39 |
| (space) | 20 |
Digits start at 30, upper-case letters at 41 and lower-case at 61, so adding 20 to the hex of a capital gives the lower-case letter.
Where each format is used
- 0x48, 0x65 and the C array: source code in C, C++, Arduino and many other languages.
- \x48\x65: string escapes in Python, Bash, JavaScript and C.
- 48:65: the notation of MAC addresses and certificate fingerprints.
- Compact 48656c6c6f: hashes, tokens and databases that store binary as hex.
How to use the converter
- Type or paste the text; the direction is already text to hex.
- Pick the encoding (UTF-8 by default) and the output format, upper or lower case, and how many bytes per line.
- Copy the result; the byte count is shown next to it.
Frequently asked questions
What is "Hello" in hex?
48 65 6c 6c 6f in UTF-8, ASCII and ISO 8859-1: one byte per letter. With 0x prefixes it is 0x48 0x65 0x6c 0x6c 0x6f.
Why does the same text give different hex in UTF-8 and UTF-16?
UTF-8 uses one byte for ASCII and more for the rest; UTF-16 uses two bytes per character (and four for emoji), in little or big endian order. The bytes differ, the characters are the same.
Is hex the same as Base16?
Yes: hexadecimal text of bytes is Base16 as defined in RFC 4648, usually in upper case there and in lower case in most tools.