Convert UTF-8 to hex

What converting UTF-8 text to hex changes, when it is the right choice, and how the result behaves when copied, shared, searched or read by assistive technology.

Converting UTF-8 text to hex writes each byte of the encoded text as a two-digit hexadecimal number. This is not a visual effect or a font. The result is a different string that records the exact bytes behind the text. That makes it a strong tool for inspecting and transporting data, and a poor substitute for anything people need to read.

Short verdict: when hex is the right choice

Use hex when you need to see or pass along the precise bytes of a piece of text. Common cases are debugging encoding problems, comparing two strings that look identical, writing byte values into code or configuration, and documenting exactly what a system received. The main benefit is that hex is unambiguous and uses only ASCII characters. The decisive tradeoff is that the meaning is no longer readable by people. The output is also larger: every byte becomes two characters, or three with a separator, and non-ASCII characters already take two to four bytes each in UTF-8. Keep plain text when people need to read, search, edit or hear the content.

  • Good fits: diagnosing mojibake or garbled characters; spotting invisible characters, stray line endings or byte order marks; checking whether two visually identical strings are actually the same; embedding exact byte values in code, tests or protocol documentation.
  • Poor fits: social posts, messages, headings, alt text, or any content meant for human readers; hiding or protecting information; text that others will need to search or edit.

What the conversion actually changes

The conversion has two steps. First, each character is encoded as UTF-8. Each Unicode code point becomes one to four bytes: ASCII letters take one byte, most accented Latin letters take two, the euro sign and many CJK characters take three, and most emoji take four. Second, each byte, with a value from 0 to 255, is written as a hex pair from 00 to FF. The stored content changes completely. Nothing is reversed, mirrored or restyled. The process is lossless: the original text can be restored exactly, as long as the reader knows the bytes are UTF-8.

Bytes versus code points

Requests to turn UTF-8 into hex sometimes actually want code point notation. These are different things. The letter é is code point U+00E9, but its UTF-8 bytes are C3 A9. In UTF-16 it would be the single unit 00E9. If a destination expects code points, such as an HTML numeric reference or a U+ value in documentation, UTF-8 byte hex is the wrong output. Confirm which form is expected before converting.

Input | Code points | UTF-8 bytes (hex) | Bytes
Hello | U+0048 U+0065 U+006C U+006C U+006F | 48 65 6C 6C 6F | 5
é (precomposed) | U+00E9 | C3 A9 | 2
é (e plus combining acute accent) | U+0065 U+0301 | 65 CC 81 | 3
€ | U+20AC | E2 82 AC | 3
😀 | U+1F600 | F0 9F 98 80 | 4
👍🏽 (thumbs up with skin-tone modifier) | U+1F44D U+1F3FD | F0 9F 91 8D F0 9F 8F BD | 8

The two versions of é look the same on screen but produce different hex. One is a single precomposed character. The other is a base letter followed by a combining mark. This is the Unicode normalization difference between NFC and NFD forms. Hex makes the difference visible, which helps with diagnosis. It also means hex taken from two sources will not match unless both sources used the same normalization.

A single visible emoji can contain several code points, as the skin-tone example shows. Cutting hex output in the middle of a byte sequence produces invalid UTF-8. Cutting it between code points can split one emoji into separate pieces, such as a plain thumbs up followed by a standalone skin-tone swatch. For the same reason, reversing the hex digits or the byte order does not reverse the text. It yields invalid or unrelated data. If you need reversed text in hex, reverse the text by grapheme cluster first, then encode it.

Hidden details the hex will expose

  • A trailing newline appears as 0A. Shell commands such as echo add one unless you suppress it.
  • Windows-style line endings appear as 0D 0A.
  • A UTF-8 byte order mark at the start appears as EF BB BF.
  • A non-breaking space appears as C2 A0 instead of an ordinary space, 20.
  • Zero-width characters, such as the zero-width space E2 80 8B or the zero-width joiner E2 80 8D used in emoji sequences, show up even though they are invisible in the text.

Output formats are not interchangeable

  • Spaced pairs (63 61 66 C3 A9) are easiest for people to scan.
  • Continuous hex (636166c3a9) is compact and common in command-line tools.
  • Prefixed forms (0x63 0x61 …) or escape sequences (\x63\x61…) suit source code. Each language has its own syntax.
  • Percent-encoding (caf%C3%A9) is a related URL format, not plain hex conversion. Unreserved ASCII characters are left as they are, and only other bytes are written as hex.
  • Uppercase and lowercase hex digits mean the same value. Some strict validators may still require one case.

Readability and usability after copying or sharing

Copy and paste: hex output contains only digits, the letters A to F, and whatever separator you chose. It therefore tends to pass through channels that would mangle non-ASCII characters. The weak points are layout, not characters. Spaces may be collapsed, and email or chat clients may wrap long lines and insert breaks that get pasted back into a decoder. Some decoders ignore whitespace and others reject it. No specific application was tested for this review, so check any destination that matters to you.

Accessibility: a screen reader meeting hex output can only announce a run of letters and numbers. It cannot convey the original words. Exactly how the string is spoken depends on the software and its settings, which this review has not tested. Wherever people need the meaning, provide the plain text as well, and present the hex as code or clearly labeled data rather than as running prose.

Search and editing: search engines and in-page find tools match the hex string, not the words it encodes, so hex content is effectively unsearchable by its meaning. Editing is fragile. Changing a single digit can turn one character into another or produce an invalid byte sequence. Strict decoders, such as Python with default settings, raise an error on invalid UTF-8. Lenient decoders substitute the replacement character U+FFFD, which is EF BF BD in UTF-8. This substitution quietly loses data.

Hex is not protection. Anyone can decode it instantly, so it neither hides nor secures content. If you use an online converter, its appearance or wording tells you nothing about whether input is logged or retained. For sensitive text, convert locally.

Converting locally

These standard methods encode text as UTF-8 and print the bytes as hex, then decode the result back. The shell examples assume the terminal passes text as UTF-8.

# Python 3.8+
text = "café"
print(text.encode("utf-8").hex(" "))                   # 63 61 66 c3 a9
print(bytes.fromhex("63 61 66 c3 a9").decode("utf-8"))  # café
# Shell: printf '%s' avoids adding a trailing newline (0a)
printf '%s' 'café' | xxd -p          # 636166c3a9
printf '%s' 'café' | od -An -tx1     #  63 61 66 c3 a9
printf '%s' '636166c3a9' | xxd -r -p # café
// JavaScript (browsers and Node.js)
const hex = Array.from(new TextEncoder().encode("café"),
  b => b.toString(16).padStart(2, "0")).join(" ");
// "63 61 66 c3 a9"

Gaps and how to check your own case

This review did not test any particular converter, messaging platform, editor or screen reader. Statements about those destinations describe general behavior, not verified results. To confirm suitability for your own workflow, run a round trip. Convert the text, paste the hex into the real destination, copy it back out, decode it as UTF-8, and compare the result with the original byte for byte. If the destination will be read by people, check separately that a plain-text version is available to them.