Hex-Dump Binary with xxd: What It Changes and When It Helps

A practical review of using xxd to hex-dump binary files: what the output represents, how reversal works, and the limits for copying, sharing and accessibility.

Is an xxd hex dump the right transformation for your use?

Use xxd when you need to see or share the exact bytes of a file: inspecting file headers, finding stray control characters or byte-order marks, comparing two binaries, or moving a small binary through a text-only channel. Its main benefit is precision. Every byte becomes two hex digits next to its offset, and nothing is hidden or interpreted.

The tradeoff is readability. A hex dump is accurate but slow for people to read, and it is much larger than the input. Plain text is the better choice when the content is ordinary readable text and your audience cares about meaning rather than bytes, when people will read it with a screen reader, or when the data is too large to share comfortably as text. In those cases, share the text itself, or a short excerpt of the dump around the bytes that matter.

What xxd actually changes

xxd does not modify the source file. It reads bytes and writes a new text representation of them to standard output or to an output file. In the default layout, each line holds an eight-digit hex offset, then up to 16 bytes as hex digits in groups of two bytes, then a column showing those bytes as printable ASCII characters. Bytes outside the printable ASCII range appear as a dot in that column.

The example below uses a 16-byte input so it fills exactly one line. The hex column can be checked byte by byte: 48 is H, 65 is e, 6c is l, 2c is a comma, 20 is a space, and 21 is an exclamation mark.

$ printf '%s' 'Hello, xxd user!' | xxd
00000000: 4865 6c6c 6f2c 2078 7864 2075 7365 7221  Hello, xxd user!

In this tool, "reverse" has a specific meaning. The -r option converts a hex dump back into binary. It does not reverse the order of characters or words, and xxd has no mirroring or font-styling function. If you are looking for reversed or mirrored text, xxd is the wrong tool. If you want to confirm what a reversal or Unicode styling tool actually stored, xxd is a good way to check.

Options that change the layout

  • -p: plain hex with no offsets or ASCII column, convenient for copying
  • -r: reverse a dump back to binary; combine with -p for plain hex input
  • -i: output a C include file style array
  • -b: show bits instead of hex
  • -c and -g: set bytes per line and bytes per group
  • -s and -l: start at an offset and limit the number of bytes read
  • -u: use uppercase hex digits

xxd is distributed with Vim, and the available options can differ between versions and builds. Check the manual page on your system before relying on less common flags in scripts.

Round-tripping a dump back to binary

$ printf '%s' 'Hello, xxd user!' | xxd -p
48656c6c6f2c20787864207573657221
$ echo 48656c6c6f2c20787864207573657221 | xxd -r -p
Hello, xxd user!

The xxd documentation states that in plain reverse mode (-r -p), extra whitespace and line breaks are allowed anywhere. That makes plain hex the more forgiving format to pass between systems. The default layout is reversed by reading the offsets and hex columns. Edits made only to the ASCII column on the right are not applied when you convert back.

Unicode, combining marks and emoji

xxd shows bytes, not characters. In UTF-8 text, any character outside ASCII takes two to four bytes and appears as the same number of dots in the ASCII column. For example, é written as a single precomposed code point is c3 a9. The same letter written as e plus a combining acute accent is 65 cc 81: one ASCII byte followed by the two bytes of the combining mark. An emoji outside the Basic Multilingual Plane takes four bytes, and emoji sequences joined with zero-width joiners take many more. This is useful for diagnosing text that looks identical on screen but is stored differently. It also means the ASCII column is not a reliable preview of non-English text.

Will the result stay readable and usable after copying or sharing?

A hex dump is plain ASCII, so it generally survives copy and paste better than raw binary does. A few practical limits still apply:

  • Line wrapping and whitespace: chat apps, email clients and word processors may rewrap lines, collapse spaces or add formatting. Plain -p output reversed with -r -p tolerates whitespace changes according to the documentation. The default layout depends on its columns staying intact.
  • Size: in the default layout, every 16 input bytes become a line of about 68 characters, which is a little over four times the input size. Dumps of large files are impractical to paste.
  • Search: searching a dump for a word works only through the ASCII column, and only when the word does not cross a line break. Searching for a hex sequence can fail when it crosses a group boundary or a line break. Plain -p output on a single line, using -c to change the line length, avoids the grouping issue.
  • Editing: editing in hex is possible, for example by filtering a buffer through xxd and back again in Vim. Only changes to the hex column take effect, and each pair of hex digits must stay a valid byte.

For accessibility, a hex dump is a poor stand-in for meaning. A screen reader will read offsets and digit groups as strings of letters and numbers, which is tedious and easy to misunderstand. No test with a specific assistive technology was supplied for this review, so how a particular screen reader handles the output is unverified. When you share a dump with people, add a plain-text sentence that explains the important part, such as "bytes 0 to 2 are a UTF-8 byte-order mark". Include the dump as supporting detail rather than the only explanation.

Behavior in specific destinations, such as a particular chat service, issue tracker or editor, was not tested for this review. If the dump must survive a particular channel, check it with a round trip: paste it, copy it back out, reverse it with xxd -r or xxd -r -p, and compare the result against the original file.

Bottom line

xxd is a sound choice when exact bytes matter and the audience can read hex. It keeps the full content intact, and plain mode is forgiving when passed through text channels. It is a poor choice for conveying meaning to general readers or for large files. In those cases, share plain text with a short dump excerpt and a written explanation.