Convert bytes to hexadecimal and view a hex dump
How to convert bytes to hex, read a hex dump, and judge whether hex output suits copying, sharing, accessibility and sensitive data.
The direct answer: what hex conversion does
Converting bytes to hexadecimal writes each byte as two hex digits from 00 to FF. The letter A, stored as the single byte 65, becomes 41. A hex dump shows the same values laid out in rows, usually with a starting offset on the left and a column of printable characters on the right. You can then inspect exactly what a file or string contains, including invisible characters, line endings and encoding details.
Hex conversion changes how data is represented. It does not change how text looks. That makes it different from the text effects it is sometimes grouped with:
- Unicode character substitution swaps ordinary letters for other code points, such as mathematical bold or small-caps lookalikes. The underlying data changes, and the result is meant to be displayed.
- CSS styling changes appearance only on a web page. The stored characters stay the same, and the styling is usually lost when the text is copied as plain text.
- Bidirectional display is how software orders right-to-left and left-to-right text on screen. The stored order stays the same.
- Hex conversion leaves the data untouched and writes out its raw byte values. Its purpose is inspection, debugging or safe transport, not display.
Characters become bytes before they become hex
Text has to be encoded into bytes before it can be shown in hex, so the result depends on the encoding. In UTF-8, basic Latin letters take one byte each and most other characters take two to four bytes. The same text encoded in UTF-16 produces different bytes. When you compare hex output from two tools, first confirm that both used the same encoding.
| Character | Code point | UTF-8 bytes in hex |
| A | U+0041 | 41 |
| é | U+00E9 | C3 A9 |
| € | U+20AC | E2 82 AC |
| א (Hebrew alef) | U+05D0 | D7 90 |
| 😀 | U+1F600 | F0 9F 98 80 |
Hex output is also a quick way to check whether text has been styled. A plain bold-looking letter stored as a mathematical alphanumeric symbol shows up as a four-byte UTF-8 sequence, not the single byte of an ordinary letter. Text that looks bold only because of CSS shows the ordinary bytes.
Converting bytes to hex with common tools
On most Unix-like systems, the command-line utilities xxd, hexdump and od can produce a hex dump of a file or of piped input. In Python, the bytes type has a hex() method. Exact column layout varies between tools and options, so check the tool's own documentation if you need a specific format.
# Hex dump of a file, with offsets and a printable-character column
xxd example.txt
hexdump -C example.txt
# Plain hex string from a short piece of text
printf 'Hello' | xxd -p
# Python: encode text to UTF-8, then convert the bytes to hex
"Hello".encode("utf-8").hex() # '48656c6c6f'
bytes.fromhex("48656c6c6f").decode("utf-8") # 'Hello'
Reading a hex dump
- Offset column: the position of the first byte in that row, itself written in hex.
- Byte columns: the data, two hex digits per byte, often grouped in pairs or blocks of eight.
- Character column: a printable rendering of each byte, with a dot or similar placeholder for bytes that are not printable. In most tools this column only interprets single bytes, so multi-byte UTF-8 characters show up as dots or as unrelated symbols there, even though the hex is correct.
- Common landmarks: 0A is a line feed, 0D 0A is a Windows-style line ending, 20 is a space, and EF BB BF at the start of a file is a UTF-8 byte order mark.
Order, reversal and right-to-left text
A hex dump lists bytes in storage order, which is the logical order of the text, not the order you see on screen. For Arabic or Hebrew, the first bytes in the dump are the first characters typed, even though they display at the right edge of the line. Mixed-direction text can look scrambled on screen while the dump shows a clean, correct sequence.
Reversing hex output character by character is not the same as reversing bytes. Reversing the string 4142 gives 2414, which swaps the digits within each byte and corrupts the data. To reverse byte order, reverse whole two-digit pairs, so 4142 becomes 4241. Reversing bytes is also different from reversing text: in UTF-8, a reversed multi-byte character turns into invalid data, so reverse the characters first and then encode if readable reversed text is the goal. Glyph mirroring, which flips how a character looks, has no counterpart in hex at all.
Limits that affect readability and reuse
Copy and paste: a plain hex string uses only the digits 0 to 9 and the letters A to F, so it generally survives being pasted into email, chat, terminals and code with no change. Hex dumps are less robust. Their alignment depends on a monospaced font and preserved spacing, and some destinations collapse spaces or wrap lines. Paste dumps into a code block or a plain-text file if their layout matters. Line breaks and spaces in pasted hex are usually harmless when converting back, but strip them first if the decoding tool rejects them.
Readability and accessibility: hex is not human-readable text. Anyone sharing information that people need to read should send ordinary text and use hex only as a supplement for technical inspection. No assistive-technology documentation or test results were supplied for this article, so it cannot say exactly how particular screen readers announce hex strings or dump layouts. A reasonable expectation is that they read digit and letter sequences that carry no meaning to the listener, and that tabular dumps are hard to navigate. Test with the specific screen reader and destination before relying on hex in accessible content.
Size: hex doubles the byte count, and dumps add offsets, spacing and the character column on top of that. For moving binary data through text-only channels, a more compact encoding such as Base64 may suit better, while hex remains easier to read byte by byte.
Handling sensitive data
Hex is not encryption or obfuscation. Anyone can convert it back to the original bytes instantly, so passwords, keys, tokens and personal data stay fully exposed in hex form. Before pasting such content into an online hex dump tool, find out whether the tool processes input locally in the browser or sends it to a server, and what it keeps. That depends on the specific service, and no documentation for any service was supplied here. If you cannot confirm local processing, use an offline command-line tool or a short local script. Redact secrets before sharing a dump to get help with debugging.
When to use hex and when to use ordinary text
- Use hex to inspect encoding problems, find hidden or invisible characters, compare files byte by byte, check whether text uses substituted Unicode styles, or describe exact byte values in bug reports.
- Use ordinary text when people need to read, search, translate or hear the content through assistive technology.
- Use hex alongside ordinary text when a reader needs both the meaning and the exact bytes, for example in technical documentation about an encoding issue.