← Back to Blog

Developers & Code | Published Aug 21, 2026 | Updated Oct 13, 2026 | 6 min read

How to Copy Hex Dumps Without Losing Alignment

By Deepender Yadav

How to Copy Hex Dumps Without Losing Alignment — Edge Drop Guide

A hex dump keeps its columns only when it travels as plain text and lands in a fixed-width (monospace) font. Generate the dump straight to the clipboard, for example Format-Hex -Path .\file.bin -Count 256 | Out-String -Width 120 | Set-Clipboard in PowerShell 7, then paste it into a code block (GitHub, Slack, Teams, Markdown), a code editor, or a document where you set the font to Consolas. In a proportional font, the offset, hex and ASCII columns drift apart.

Make the dump and copy it as plain text

PowerShell 7

Format-Hex -Path .\file.bin -Count 256 | Out-String -Width 120 | Set-Clipboard

-Count limits the dump to the first 256 bytes, and -Offset starts it further into the file. PowerShell 7 prints a 16-digit offset, which makes each line wider than 80 characters, so Out-String -Width 120 stops lines from wrapping or being cut at the console width before they reach the clipboard.

Windows PowerShell 5.1

-Count and -Offset arrived in PowerShell 6.2, so in Windows PowerShell 5.1 read the bytes first and pass them in:

$bytes = [byte[]](Get-Content -Path .\file.bin -Encoding Byte -TotalCount 256)
Format-Hex -InputObject $bytes | Out-String -Width 120 | Set-Clipboard

For a small file, Format-Hex -Path .\file.bin | Out-String -Width 120 | Set-Clipboard dumps the whole thing.

xxd in Git Bash or WSL

xxd comes with Vim. Git for Windows includes it in Git Bash, and WSL distributions have it when Vim is installed:

xxd -g 1 -l 256 file.bin | clip.exe
  • -g 1 groups the hex by single bytes instead of the default pairs, which most people find easier to read.
  • -l 256 stops after 256 bytes, and -s sets a starting offset.
  • -c 8 puts 8 bytes on each line instead of 16. Use it when the dump will be read on a narrow screen, such as a chat app on a phone.
  • clip.exe is the Windows clipboard tool, callable from Git Bash and WSL. A hex dump is plain ASCII, so it arrives unchanged.

Both tools pad the columns with spaces, not tabs, so the alignment doesn't depend on the destination's tab width.

Paste it where the columns survive

DestinationWhat to do
VS Code, Notepad and other plain-text or code editorsPaste directly; they use fixed-width fonts by default
GitHub or GitLab issues, pull requests, READMEsPaste inside a fenced code block: three backticks on the line before and after, optionally with text after the opening backticks to turn off syntax colouring
Slack and Microsoft TeamsPaste inside a code block (three backticks before and after)
Word, Outlook and OneNotePaste as plain text (the Keep Text Only paste option), then set the font to Consolas or Courier New

Labelling the block text matters in Markdown: language highlighting such as js colours random fragments of hex as if they were code. Which apps understand Markdown from the clipboard covers where code fences work, and how to keep line breaks when pasting into Slack covers Slack's formatting.

Why the alignment breaks

Plain text on the clipboard is only characters; it carries no font. The columns line up because every character in the dump takes the same width, which is only true in a fixed-width font. Paste the same text into a document that uses a proportional font such as Calibri and narrow characters like 1 and . take less space than 0 or F, so each line drifts by a different amount.

The other common causes:

  • Wrapping: a destination narrower than the line folds the ASCII column onto the next line. Widen the window, or produce fewer bytes per line (xxd -c 8).
  • Rich-text paste: pasting with formatting into Word or Outlook brings the source app's styling along. How to paste without formatting covers the shortcuts, and pasting code into Word, email and chat covers the same problem for source code.
  • Collapsed spaces: outside a code block, some chat and web editors collapse runs of spaces into one. A code block keeps them.

Keep a copy as a file

If you'll refer to the same dump repeatedly, save it rather than re-copying it: xxd -g 1 -l 256 file.bin > dump.txt, or ... | Out-String -Width 120 | Set-Content dump.txt in PowerShell. Open the file and copy the lines you need each time. Clipboard history is fine for the next few pastes, but Windows clipboard history clears unpinned items when the PC restarts, and it never stores files. The PowerShell clipboard cheat sheet has more ways to move command output to and from the clipboard.

FAQ

How do you copy just the hex bytes?

Use xxd -p file.bin, which prints plain hex such as 48656c6c6f with no offsets and no ASCII column. There are no columns to lose, which suits pasting into code or a tool that expects raw hex.

Why does a dump look aligned in VS Code but not in Outlook?

VS Code uses a fixed-width font and Outlook's default message font is proportional. Paste with Keep Text Only and change the font of the pasted lines to Consolas.

How do you turn a hex dump back into a file?

xxd -r reverses a dump made by xxd into binary: xxd -r dump.txt > file.bin. It expects xxd's own layout, so it won't read Format-Hex output.

Related reading

Sources

Deepender Yadav
Written by Deepender Yadav · Creator & Developer

Deepender Yadav created Edge Drop and builds and tests it, from the edge-hover shelf to each release. A B.Tech Computer Science Engineering student, Deepender writes the Edge Drop guides, comparisons and developer posts, and checks product details against the app's source code.

GitHub · LinkedIn

Copy. 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
Find us on CodeHype