Text to Hex

Text to hex bytes — UTF-8 encoded, two digits each, in the form you would paste into a dump, an escape sequence or a literal.

Runs 100% in your browserNothing is uploaded to a serverFree forever

Text

Hexadecimal

Copied!

Two hex digits per byte, always

Text becomes hex in two steps: encode the characters to bytes with UTF-8, then write each byte as exactly two hex digits. The "exactly two" is what makes the output parseable — 0A and A are the same number, but only the padded form can be read back unambiguously from a stream where the bytes are not separated.

Hex is the notation of choice here rather than binary because it is four times shorter and still maps cleanly onto byte boundaries. A sentence in binary is a wall; the same sentence in hex is something you can scan.

What a hex dump looks like

Tools like xxd, hexdump and every binary editor lay bytes out in fixed-width rows with an offset on the left and a printable rendering on the right. Non-printable bytes show as a dot, which is why the dump below has one at the end — the trailing newline:

A hex dump of “Hex is just bytes.”, eight bytes to a row
OffsetBytesAs text
0000000048 65 78 20 69 73 20 6AHex is j
0000000875 73 74 20 62 79 74 65ust byte
0000001073 2E 0As..

The offset column is a byte count from the start of the data, in hex. That is the number a debugger, a parser error or a diff will quote at you, so being able to line it up against the row is most of what reading a dump is.

Where the hex is going

The same bytes get written several different ways depending on what will read them, and picking the wrong form is a common source of "the value looks right but does not work":

The same two bytes, written for different readers
Where you would write itForm
C, Python, JavaScript string\x48\x69
a numeric literal0x4869
percent-encoding in a URL%48%69
an HTML numeric entityHi
a Unicode code pointU+0048 U+0069

Percent-encoding in particular is not the same job as hex: it only escapes the bytes a URL cannot carry literally, leaving the rest as characters. If that is what you need, use the URL encoder instead of pasting a full hex string into a query parameter.

Non-ASCII costs more than one byte

Every character above U+007F takes two to four bytes in UTF-8, so its hex is four, six or eight digits rather than two. That is why a string's character count and its hex length are not related by a constant, and why truncating a hex string at an arbitrary even offset can cut a character in half.

Related: hex to text for reading a dump back, text to binary when you want the individual bits, and the hash generator if what you actually want is a digest of the bytes.

More developer tools