How to Copy Hex Dumps Without Losing Alignment
A hex dump is a developer artifact where column alignment is the whole point. The byte offset, the hex pairs, and the ASCII rendering line up so a reader can scan down a column and spot a byte that is wrong. The Windows clipboard is, by default, a plain-text transport: it strips monospace formatting the moment the source application hands the bytes to the OS, and any destination that does not render in a monospace font will collapse the alignment. Copying a hex dump is therefore a two-step problem — getting the bytes onto the clipboard intact, and getting them into a destination that respects the columns. This guide covers both steps on Windows, with attention to which clipboard formats survive the trip and which destinations are safe.
For neighbouring topics, see copying error logs without taking half the console, SQL clients: result grids to clipboard, and best clipboard habits for developers in 2026. The Windows clipboard history limit of 25 items and 4 MB per item applies; see Windows clipboard settings, line by line for the full breakdown.
What a hex dump actually is
A hex dump is a fixed-width text rendering of binary bytes. A typical line, produced by xxd, looks like this:
00000000: 4865 6c6c 6f20 576f 726c 6421 0a00 0000 Hello World!....
00000010: 0102 0304 0506 0708 0900 0000 0000 0000 ................
Three columns: an 8-digit offset, a hex region split into groups, and an ASCII region. Every column has a fixed character width. The ASCII region uses . for non-printable bytes. The offset column increments by the number of bytes per line, usually 16.
The alignment is the value. If the offset column drifts by one character, the reader cannot scan offsets vertically. If the hex pairs collapse, byte-level debugging becomes guesswork. The columns survive only when the destination uses a monospace font and does not strip whitespace.
What the Windows clipboard carries
Windows clipboard history stores three formats per item: plain text, HTML, and bitmap. Files are not first-class history cards; they ride as HDROP references that the history panel does not surface as a card. Each item is capped at 4 MB. Unpinned entries clear on restart; sync, when enabled, is text-only and off by default.
For hex dumps, the relevant format is plain text. Most terminals and hex viewers expose a Copy command that places UTF-8 or UTF-16 text on the clipboard. Some also place an HTML representation alongside the text. The destination picks whichever format it prefers: a plain text editor takes the text, a rich text editor takes the HTML.
The problem is that plain text on the clipboard does not carry font information. It carries characters only. Whether the columns line up after pasting depends entirely on the destination's default font.
| Clipboard format | Carries alignment? | Survives paste into Notepad? |
|---|---|---|
| Plain text | Yes, as spaces | Yes |
| HTML | Yes, with font hint | No (Notepad ignores HTML) |
| Bitmap | Yes, as pixels | No (Notepad does not paste bitmaps) |
A hex dump copied as plain text will align in any monospace editor. The same dump copied as HTML and pasted into a rich text editor that defaults to a proportional font will lose alignment unless the HTML carries a monospace style.
Producing a hex dump on Windows
Three tools cover most needs: xxd (in Git Bash, WSL, or Vim), Format-Hex (built into PowerShell), and certutil -dump (built into Windows). Each has a different default column width, and each interacts with the clipboard differently.
xxd
xxd is the canonical hex dumper from the Vim distribution. In Git Bash or WSL:
xxd -g 1 file.bin | head -n 16
The -g 1 flag forces one-byte groups, which is what most reviewers expect. The default is two-byte groups. Pipe to head to avoid pasting a 50,000-line dump.
To copy the first 16 lines straight to the clipboard in Git Bash:
xxd -g 1 -l 256 file.bin | clip
clip is the Windows clipboard utility. It accepts stdin and places it on the clipboard as plain text. The same clip works from cmd and PowerShell.
Format-Hex
Format-Hex is a PowerShell cmdlet available in PowerShell 5.1 and later. Its default output is closer to od than to xxd:
Format-Hex -Path file.bin -Count 256
The output uses 16 bytes per line, with a 0000000000000000 style offset, hex pairs, and an ASCII column. To copy:
Format-Hex -Path file.bin -Count 256 | Out-String | clip
Out-String is necessary because clip does not accept PowerShell's formatted objects directly; it needs a string.
certutil
certutil -dump file.bin produces a verbose hex dump intended for certificate inspection, but it works on any file. The output mixes metadata and hex, which makes it less useful for byte-level debugging. Prefer xxd or Format-Hex.
Where hex dumps survive
The rule is simple: monospace destinations only. The following destinations preserve column alignment when the source is plain text:
- VS Code — any
.txt,.log, or code file. The default font is monospace. Paste, then immediately wrap the dump in a fenced code block if the file is Markdown. - JetBrains IDEs — same behaviour, monospace by default.
- Windows Terminal and Windows Console — paste into the terminal buffer; the buffer is monospace. Note that terminals may wrap long lines, so keep dump lines under the terminal width.
- Notepad — plain text editor, monospace is not the default but the columns survive because Notepad does not strip whitespace. The font is Lucida Console or Consolas depending on version; both are monospace.
- Markdown code fences — paste inside triple backticks. The rendered output uses the site's monospace font.
Destinations that usually break alignment:
- Microsoft Word — default font is proportional. Paste as plain text (Ctrl+Shift+V in some configurations, or
Paste Special → Unformatted Text) and then select the dump and apply a monospace font such as Consolas. - Outlook HTML email — same problem as Word. Use
Paste Special → Keep Text Onlyand apply a code style. - Slack and Microsoft Teams chat — both render monospace inside backticks. Paste the dump inside triple backticks for a multi-line block. Without the backticks, alignment is lost.
- OneNote — proportional default font. Apply a code style or paste into a OneNote code block.
Keeping alignment in Markdown
The cleanest pattern for sharing a hex dump in a Markdown issue, PR comment, or README is to wrap it in a fenced code block and label the language as text or plain:
<pre>
00000000: 4865 6c6c 6f20 576f 726c 6421 0a00 0000 Hello World!....
00000010: 0102 0304 0506 0708 0900 0000 0000 0000 ................
</pre>
The text label tells most renderers not to apply syntax highlighting, which can otherwise shift widths through token styling. Avoid PH6 js for hex dumps; the highlighting is meaningless on hex data and can visually break the columns.
GitHub, GitLab, Azure DevOps, and Bitbucket all render fenced code blocks in a monospace font with consistent line height. The dump survives intact.
Common failure modes
Wrapped lines in terminals
A 16-byte-per-line xxd dump line is about 76 characters wide. A Windows Terminal at the default 120-column width fits it. If the terminal is narrower — for example, docked to a side panel — the dump wraps, and the ASCII column lands on the next line. Either widen the terminal before pasting, or pipe through cut -c 1-76 to truncate the ASCII column.
Tab characters in the dump
Some hex dumpers separate columns with tabs rather than spaces. xxd uses spaces. Format-Hex uses spaces. od -A x -t x1z uses spaces. If a tool is configured to use tabs, the destination's tab width determines alignment, and tabs are not consistent across editors. Convert tabs to spaces before copying:
xxd file.bin | expand -t 1 | clip
Smart quotes and dash substitution
Some rich text editors substitute ASCII characters with Unicode equivalents: " becomes ", -- becomes —. This is rare for hex dumps because the characters are digits and spaces, but it does happen for the ASCII column when the dump contains quote characters. The fix is to paste as plain text only.
Trailing whitespace stripping
Some editors strip trailing whitespace on save. Hex dump lines have no trailing whitespace, so this is usually safe, but if a dump is padded with trailing spaces to a fixed width, the padding is lost and the next paste of that text will not align.
Putting a hex dump on the shelf
A hex dump that needs to be referenced repeatedly — say, while debugging a file format — is a candidate for a clipboard shelf rather than Win+V. The shelf holds the dump, the user drags it into the editor when needed, and the dump leaves the shelf as text. The 4 MB per-item limit is generous for hex dumps: a 256-byte dump is about 1.5 KB of text; a 4 KB binary file as a full xxd dump is about 24 KB of text. Even a 64 KB binary file fits comfortably.
For more on how shelves and Win+V differ, see Win+V vs a clipboard manager: honest split. The shelf does not change the alignment rules — the destination still has to be monospace — but it does keep the dump available across restarts if pinned, where Win+V clears unpinned entries on restart.
Pinning a dump for a debugging session
When a hex dump is the working artifact for a debugging session, the workflow that survives longest is:
- Produce the dump once, with
xxd -g 1 -l 256 file.bin. - Save the dump to a file in the project, e.g.
docs/repro/dump.txt. This is the canonical copy. - Copy the dump, or open the file and copy the relevant excerpt, when pasting into a chat or issue.
- If the same dump will be pasted multiple times in one session, pin it in Win+V (or a shelf) so the pinned copy survives the 25-item eviction.
- Clear the pin when the debugging session ends. Pinned items persist across restarts, and a stale hex dump pinned for weeks is clutter.
This mirrors the broader developer habit of treating the clipboard as a short-term buffer, not a snippet store. For the full habit set, see best clipboard habits for developers in 2026.
A short checklist
- Produce the dump with
xxd -g 1orFormat-Hex. Avoidcertutil -dumpfor byte-level work. - Pipe through
clipto put the dump on the clipboard as plain text. - Paste into a monospace destination. If the destination is rich text, paste as plain text and apply a monospace font.
- Wrap the dump in a fenced
textcode block when sharing in Markdown. - Save the canonical copy to a file in the repo. The clipboard is the transport, not the store.
Background for this constraint is Markdown READMEs: Screenshots as Files in /docs.
Related reading
- SQL Clients: Result Grids to Clipboard
- Markdown READMEs: Screenshots as Files in /docs
- Best Clipboard Habits for Developers in 2026
- Clipboard Tools on Multi-Monitor Windows Setups
Sources
- Microsoft Support — Using the clipboard on Windows — official statement of the 25-item / 4 MB / text-HTML-bitmap clipboard history limits that govern how a hex dump is stored
- Microsoft Learn — Clipboard formats (Win32) — official list of registered clipboard formats, including CF_TEXT, CF_UNICODETEXT, CF_HTML, and CF_DIB, which determine what a hex dump carries across apps
- Microsoft Learn — Format-Hex cmdlet reference — official documentation for the PowerShell cmdlet that produces a hex dump on Windows
- Vim documentation — xxd man page — the canonical xxd manual, hosted in the Vim source tree, documenting the
-g,-l, and-pflags - GitHub Docs — Creating and highlighting code blocks — official guidance on fenced code blocks in Markdown, which preserves hex dump alignment when shared on GitHub
Deepender Yadav is a B.Tech Computer Science Engineering student and software developer interested in building practical software and open-source projects.
GitHub · LinkedInCopy. Stack. Drop.
Transform your clipboard into an interactive edge shelf. Stack, pin, and drag assets into any app with zero friction.
Download for Windows Get from Microsoft Store
How to Install Guide · First 10 Minutes Guide · Drag & Drop Guide · Edge-Drop vs Win+V · Support
Free · Lightweight · Privacy First