Text to Hex Converter

Text to hex converter: type or paste text and get its hexadecimal bytes. Choose UTF-8, UTF-16, ASCII, Latin-1 or Windows-1252, then the separator, prefix and letter case. Each character's bytes are listed. Nothing leaves your browser.

Use Text to Hex for Unicode characters; use ASCII to Hex for ASCII character codes.

Text to hex
9 characters
15 bytes · UTF-8
Ctrl+Enter runs · your input stays in this browser
Hex dump, xxd style (15 bytes)
00000000: 4772 c3bc c39f 652c 20e4 b896 e795 8c    Gr....e, ......

How text is converted to hexadecimal

Text is not stored as letters. A computer stores numbers, and a text encoding is the agreement about which number stands for which character. Converting text to hex is therefore two steps: encode the characters into bytes with a chosen encoding, then write each byte as two hex digits. The encoding step is where the differences come from, because the same string can be a different series of bytes depending on the encoding.

The German word Grüße shows both steps. Five characters become seven bytes in UTF-8, because ü and ß are each two bytes long, and the seven bytes are written as 14 hex digits.

Grüße encoded as UTF-8
ByteHexDecimalPart of
14771G
272114r
3C3195ü
4BC188ü
5C3195ß
69F159ß
765101e

The bytes C3 BC are one character. Counting hex digits and dividing by two gives the size in bytes and says nothing about the number of characters, which is also why the output of this converter is longer than the input suggests when the text has accents or symbols.

It helps to keep three things apart. A character is what you see. A code point is the number Unicode assigns to it, written U+00FC for ü. A byte is what ends up in the hex, and the bytes for one code point depend on the encoding. Hex written from code points (00FC) and hex written from UTF-8 bytes (C3 BC) are both legitimate, they answer different questions, and mixing them up is the commonest reason a converted value is rejected by the system that receives it. This converter always produces bytes.

How many bytes one character takes in UTF-8, UTF-16 and Latin-1

UTF-8 uses one byte for the 128 ASCII characters and up to four for the rest. UTF-16 uses two bytes for the first 65,536 code points and four for the others, in pairs called surrogates. Latin-1 and Windows-1252 use one byte for every character they have and cannot represent the rest at all. The characters below were chosen to hit each case.

Characters and their UTF-8 bytesA is U+0041 and the bytes 41; é is U+00E9 and the bytes C3 A9; € is U+20AC and the bytes E2 82 AC; 😀 is U+1F600 and the bytes F0 9F 98 80.AU+0041411 byteéU+00E9C3A92 bytes€U+20ACE282AC3 bytes😀U+1F600F09F98804 bytes
One character is one to four bytes in UTF-8, so the hex of a string is not always two digits per character.
The same character in different encodings (hex bytes)
CharacterUTF-8UTF-16 LEUTF-16 BELatin-1Windows-1252
A U+00414141 0000 414141
é U+00E9C3 A9E9 0000 E9E9E9
€ U+20ACE2 82 ACAC 2020 ACnot possible80
中 U+4E2DE4 B8 AD2D 4E4E 2Dnot possiblenot possible
😀 U+1F600F0 9F 98 803D D8 00 DED8 3D DE 00not possiblenot possible

UTF-16 stores 😀 (U+1F600) as the surrogate pair D83D DE00, which is why it takes four bytes in either order. The euro sign is the usual trap for single-byte encodings: it is 80 in Windows-1252 but does not exist in Latin-1, so the same text can be encodable in one and not in the other. The mapping tables are in the WHATWG Encoding Standard.

Hex output formats: separators, prefixes and letter case

Hex has no single written form. Debuggers print 48 65 21, source code wants 0x48, 0x65, 0x21, URLs want %48%65%21 and databases often want 486521. The bytes are identical; only the packaging differs. Pick the form the destination expects, because a prefix that one parser requires another rejects. The text is Hi!, and the converter produces every one of these from it.

Hi! in seven hex notations
FormatOutput
Plain486921
Spaces, upper case48 69 21
Colons48:69:21
Comma and space48, 69, 21
0x prefix0x48, 0x69, 0x21
\x escapes\x48\x69\x21
Percent%48%69%21

Letter case does not change the value, but it matters when strings are compared as text: a1 and A1 are different strings that name the same byte. Hash digests are traditionally written in lower case, memory addresses and color codes often in upper case. If you compare hex from two sources as plain strings, normalize the case first.

Why two tools give different hex for the same text

When the output of two converters disagrees, the cause is almost always one of four things.

If you need to match hex from another system, find out which of these it uses and select the same options. The decoder on the main page shows the byte table, which is the quickest way to compare two sources byte by byte.

Hex in source code: how languages escape characters

Programming languages let you write a character by its number inside a string, but each one uses a different notation and a different meaning for the digits. A \x escape is a byte or a single code unit; a \u escape is a Unicode code unit or code point. Copying hex from this converter into a string literal works only if the language reads the escape the same way.

The euro sign (U+20AC) and the emoji 😀 (U+1F600) as escapes
LanguageEuro signEmojiNote
C, UTF-8 string literal\xE2\x82\xAC\xF0\x9F\x98\x80Each \x is one byte of the UTF-8 form
Python 3 string\u20ac\U0001f600\x allowed only up to 0xFF, as a code point
Python 3 bytesb"\xe2\x82\xac"b"\xf0\x9f\x98\x80"The same UTF-8 bytes
JavaScript\u20AC\u{1F600}Also \uD83D\uDE00 as two code units
JSON\u20ac\ud83d\ude00Code points above FFFF need a surrogate pair
URL%E2%82%AC%F0%9F%98%80Percent-encoding of the UTF-8 bytes

The practical rule: to paste UTF-8 bytes into C, a Python bytes literal or a URL, use the converter with the 0x or \x prefix and UTF-8 encoding. To write a character into a JavaScript, JSON or Python string, use its code point (the U+ value) with \u, not the UTF-8 bytes, because \xE2\x82\xAC in a Python string is three Latin-1 characters and no euro sign.

Text to hex in Python, JavaScript and the shell

Python
"Hello".encode("utf-8").hex()          # '48656c6c6f'
"Hello".encode("utf-8").hex(" ")       # '48 65 6c 6c 6f'   (separator argument, Python 3.8+)
JavaScript
Buffer.from("Hello", "utf8").toString("hex")          // '48656c6c6f'

// Browser, no Buffer:
Array.from(new TextEncoder().encode("Hello"), b => b.toString(16).padStart(2, "0")).join(" ")   // '48 65 6c 6c 6f'
Command line and PowerShell
printf 'Hello' | xxd -p                 # 48656c6c6f
printf 'Hello' | od -An -tx1            # 48 65 6c 6c 6f

([Text.Encoding]::UTF8.GetBytes("Hello") | ForEach-Object { $_.ToString("X2") }) -join " "   # 48 65 6C 6C 6F

Note that echo Hello | xxd -p without -n or printf adds a trailing 0A, because echo ends its output with a line feed. That extra byte is the most frequent reason a command-line result is one byte longer than the one from a converter.

Where hex-encoded text is used

Hex lets binary-unsafe systems carry arbitrary text. SQL has a hex string literal for exactly this: X'48656C6C6F' is standard SQL, and MySQL also accepts 0x48656C6C6F. PostgreSQL writes binary data as a hex string in the form '\x48656c6c6f' when the type is bytea. In each case the database stores the bytes, and what they mean as text depends on the column's character set when you read them back.

HTML has its own hex notation for characters: the numeric reference H is the letter H and 😀 is the emoji, written by code point rather than by UTF-8 byte. URLs use percent-encoding for the UTF-8 bytes, as in RFC 3986, so the string Grüße appears in an address as Gr%C3%BC%C3%9Fe. Hex also shows up in log files and in debugging output where a string may contain characters that would corrupt the log, so each byte is written out instead.

Checking the result by converting it back

A round trip is the simplest test. Paste the hex into the hex decoder with the same encoding and the original text should come back, and a mismatch tells you which side picked a different encoding. The swap button in the tool does this in one click: the output becomes the input of the reverse direction. The length check is separate: divide the hex digit count by two and compare with the byte count the converter reports under the output.

For text you intend to send over a channel that carries only letters and digits, Base64 is shorter than hex, at four characters for every three bytes against six for hex, and the two forms can be converted into each other. For ASCII-only text, ASCII to hex has the lookup tables.

Questions about converting text to hex

Why is the hex of my text longer than I expected?

Each byte is two hex digits, and each character can be several bytes. Plain English letters are one byte each, so 5 letters give 10 digits. An accented letter is two bytes in UTF-8 and an emoji is four, so a short string with symbols grows quickly.

Which encoding should I choose?

Use UTF-8 unless a system tells you otherwise. It is what web pages, JSON and most APIs expect. Choose UTF-16 for Windows internals and Java or .NET memory dumps, and ASCII or Latin-1 only when the receiving side is limited to one byte per character.

What happens to characters the encoding cannot hold?

The converter reports the character and its position, and writes 3F (a question mark) in its place so the length stays right. A euro sign cannot be written in ASCII or Latin-1, for example. Switch to UTF-8 or Windows-1252, which has the euro sign at 80.

Does a new line add bytes?

Yes. A line break in the input box is one character, a line feed, written 0A. Text copied from a Windows file may contain a carriage return as well, 0D 0A. If your hex has an extra 0A at the end, the input ended with a line break.

Is text to hex the same as encryption?

No. The output is the same data in another notation, and anyone can turn it back into text with a hex decoder. It hides nothing.