For anyone working with raw binary files, the xxd utility is an indispensable tool in your toolkit. As a hex editor, it lets you directly view, analyze, and manipulate the contents of binaries down at the bit level.
While xxd originated on Linux and UNIX, it can be installed and used effectively on Windows as well. In this guide, I‘ll show you step-by-step how to get xxd running on your Windows machine.
By the end, you‘ll be able to:
- Examine executable files, disk images, and other binary formats in hexadecimal
- Edit and patch binaries by modifying their hex dump
- Convert files to and from human-readable formats
- Automate binary manipulation tasks with scripts
- Understand low-level encoding and structure of files
So if you‘re ready to unlock the full power of hex editing on Windows, let‘s get started!
What Exactly is xxd and Why Use It?
The xxd utility is used to create a hex dump or hexa decimal representation of any binary file. It transforms the raw octets and bits that make up a binary into a format that is human readable and editable.
Some of the key features and uses of xxd include:
-
Viewing executables, disk images, bytecode, and other binary formats in hex or ASCII. Ever wanted to peek inside a program binary to see what‘s going on under the hood?
xxdgives you a window into its hidden hexadecimal contents. - Editing and patching binaries by modifying the hex dump. Making code changes directly in hexadecimal is insanely powerful. You can hack binaries in ways that are impossible with normal text editors.
-
Inspecting raw network packets and protocol data.
xxdhelps you analyze low-level network traffic to understand communication structures. -
Recovering corrupted files and forensic analysis. When a file won‘t open normally,
xxdcan help extract readable contents from its raw binary form. -
Converting to and from different text encodings. Ever needed to quickly convert a text file from ASCII to UTF-16 or other formats?
xxdmakes this a breeze. - Scripting and automating binary manipulations. The text-based output integrates smoothly with Unix pipes and command chaining. Automate complex binary tasks with a few lines of scripting.
- Learning about data storage and encoding. Seeing your data in hexadecimal provides insight into how text, graphics, and other content are encoded at the lowest level.
In the age of increasing binary data, xxd is an indispensable tool for programmers, sysadmins, infosec professionals, and power users who need fine-grained control over bytes and bits. It‘s available by default on most Linux distros, and thankfully can also be used directly on Windows!
Downloading and Installing xxd on Windows
Since xxd is not included natively in Windows, we need to install it as part of a Linux toolchain or package. There are a few options, but I recommend using Git for Windows as it provides just what we need without extra overhead.
Here are the simple steps to get xxd installed:
Step 1) Download Git for Windows
First, download the latest 64-bit Git for Windows installer from the official website. The download is around 100 MB and will take a minute or two on most connections.
Once it finishes, run the installer .exe file to launch the wizard.

Step 2) Install Git and accept license
The Git setup wizard will launch. Accept the license agreement and keep clicking Next to accept the default settings.
Git and some common Linux command-line tools will be installed to C:\Program Files\Git.
Make sure you leave the Git Bash component enabled, as we‘ll use this terminal to run xxd.

Step 3) Launch Git Bash and verify xxd
After it finishes installing, you should find Git Bash in your start menu. Launch the terminal.
To verify xxd is available, enter xxd --version and hit enter:
$ xxd --version
xxd V01.01 (01.13.20), compiled with cygwin, using Python 2.7.
Copyright (C) 1990-2007 Mark Adler, all rights reserved.
Seeing the version string indicates that xxd was installed correctly! It‘s now ready to use from your Git Bash terminal just like on Linux.
We have xxd installed, but it‘s only available from Git Bash currently. Let‘s set up Windows so we can call it from Command Prompt as well.
Setting Up PATH Environment Variable for xxd
Windows uses the PATH environment variable to store directories containing executable programs. By adding Git‘s bin folder containing xxd to PATH, we can launch xxd from Command Prompt just like any other Windows executable.
Here are the steps to add the Git bin path to your PATH variable:
Step 1) Open PATH system settings
Open the start menu and search for "environment variables" to launch the control panel applet.
Click the Environment Variables button on the bottom.

Step 2) Edit the Path variable
Under System variables, scroll down and find the variable named Path. Click the Edit button.

Step 3) Append new Git path
In the Edit environment variable window, click New to add a new path directory.
Enter the Git bin folder path:
C:\Program Files\Git\bin

Step 4) Test xxd from Command Prompt
Click OK to accept the changes and close all windows.
The Git bin path containing xxd has now been added to the main Windows PATH.
To confirm, open a new Command Prompt window and type xxd --version. It should now print the version string just like in Git Bash!
With xxd installed and available system-wide, you‘re ready to start hex editing like a pro!
Converting Files to Hex With xxd
Now let‘s go over how to use xxd for its main purpose – generating hex dumps from binary files. This allows you to visualize and inspect the raw byte contents of any file on disk.
The basic syntax for a hex dump is:
xxd [options] input_file
This will convert input_file to hexadecimal/ASCII and print the output. The most useful options include:
-b: Output in binary rather than hex-c: Canonical hex+ASCII format (very useful)-g: Group output by N bytes per line-l: Limit output to N bytes-s: Skip N bytes of input before conversion
Let‘s look at examples of converting different binary types to hex.
Hexdump a Windows Executable
To peek inside Windows programs, we can dump EXE and DLL files. Let‘s try the notepad.exe binary:
> xxd notepad.exe
This generates pages of hexadecimal bytes and ASCII text:
00000000: 4d5a 9000 0300 0000 0400 0000 ffff 0000 MZ..............
00000010: b800 0000 0000 0000 4000 0000 0000 0000 ........@.......
00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000030: 0000 0000 0000 0000 0000 0000 0e1f ba0e ................
00000040: 00b4 09cd 21b8 014c cd21 5468 6973 2070 .....!..L.!Thisp
00000050: 726f 6772 616d 2063 616e 6e6f 7420 6265 rogramcannotbe
00000060: 2072 756e 2069 6e20 444f 5320 6d6f 6465 runinDOSmode
We can see the initial MZ bytes indicating this is a Windows PE binary. By analyzing the hex, we could start to reverse engineer aspects of how the program works under the hood!
Hexdump a Drive Image
Disk images are often used in forensics and data recovery. Let‘s examine a sample drive image disk.img:
> xxd -c disk.img
The -c option formats the output nicely with both hex and ASCII:
00000000: 4645 4430 3031 2100 0100 3600 0000 0000 FED001!....6.....
00000010: 0200 0000 0200 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 2000 0000 ee90 d88e ........ .......
00000030: 9890 d88e f88e d88e 0000 0000 0000 0000 ................
00000040: a800 0000 0000 0000 0000 0000 0000 5558 ..............UX
00000050: 4258 2000 7372 2044 6973 6b20 496d 6167 BX .sr DiskImag
Looking at the ASCII sections on the right, we can start to identify snippets of data. This would allow a forensics analyst to extract evidence from the disk image.
Hexdump a Text File
Even plain text files contain hidden binary data underneath. Let‘s use xxd to transform a text file into its raw representation:
> xxd sample.txt
The output reveals the ASCII characters in the file and their corresponding hex values:
00000000: 5468 6973 2069 7320 6120 7361 6d70 6c65 Thisisa sample
00000010: 2074 6578 7420 666f 7220 7465 7374 696e text for testin
00000020: 6720 6f75 7420 7468 6520 7878 6420 636f g out the xxd co
00000030: 6d6d 616e 642e 0a00 mmand...
The newline is shown as 0a in hex. We can see how the text is encoded under the hood!
These examples demonstrate how xxd can be used to explore and analyze the contents of virtually any binary file by viewing it in hexadecimal.
Next let‘s go through some more practical examples of editing binaries with xxd.
Advanced xxd Commands for Binary Manipulation
In addition to static dumps, xxd can also modify, convert, and transform binaries in powerful ways. By working with the hex dump, you can achieve low-level changes that are difficult through normal editing.
Some useful operations include:
Extracting Specific Data Ranges
You can print only a subset of bytes from a file using the -s and -l options:
xxd -s 0 -l 64 image.png
This prints the first 64 bytes, letting you extract a header or snippet.
Converting Hex Back to Binary
The -r option converts a hex dump back into binary format:
xxd -p image.png > image.hex
xxd -r -p image.hex > image-new.png
It first hexdumps to a file, then converts back to a binary PNG.
Inserting Data into Files
You can insert data by dumping to stdout, appending data, then converting back:
xxd file.bin | xxd -r -s 16 /dev/stdin file-out.bin
This adds 16 bytes from stdin before restoring the output file.
Patching and Editing Binaries
By modifying hex values in a dump, you can patch binaries in ways hex editors can‘t:
echo Hello > hello.txt
# Hexdump
xxd hello.txt > hello.xxd
# Edit hex
sed ‘s/llo/lol/‘ hello.xxd > hello-new.xxd
# Convert back to binary
xxd -r hello-new.xxd > hello-patched.txt
This replaces text in the hexdump before restoring the file.
As you can see, xxd opens up many possibilities for scripting automated binary manipulation and processing workflows.
Next let‘s go over some tips for using it effectively.
Tips for Mastering the xxd Hex Editor
Here are some handy tips for mastering xxd based on my experience using it for hex editing:
-
For quickly viewing files, use
-cfor a clean canonical format. Add-gto group the output into 4-byte lines. -
Extract sections of large files using
-sfor skip and-lfor length limiting. -
Learn to pipe
xxdoutput tosed,awk,grepetc for filtering and transformations. -
Keep the
xxdmanpage handy for looking up obscure options like-i,-p,-vwhen needed. -
Prefer
-rconversion over manually editing hex to avoid introducing errors. -
Use
/dev/stdinand/dev/stdoutfor piping data in/out rather than temporary files. -
For consistent round-trip conversion, use
-pand avoid line number prefixes when dumping. - Viewing unicode and ASCII-encoded text in hex helps explain how encodings work under the hood.
- Keep an eye out for readable ASCII text when analyzing unknown binary formats for clues.
- Always wrap filenames/paths in quotes in case they contain spaces or special characters.
Get comfortable with experimenting and you‘ll soon be manipulating binaries like a pro!
Conclusion
While xxd started as a Linux and UNIX utility, it can be installed on Windows and provides immense power for hex editing right from the command line. With some practice, you‘ll find it indispensable for daily work with binary file formats.
Some of the skills you can unlock by mastering xxd include:
- Viewing and reverse engineering executables, disk images, byte code, and other binary formats by understanding their hex contents.
- Modifying and patching program binaries in ways that are impossible through normal text editing.
-
Automating complex binary manipulation workflows by scripting
xxdcommands. - Analyzing network traffic, cryptography, file headers, data encoding, and other low level structures by viewing their binary representation.
- Recovering corrupted files and forensic analysis by extracting data from raw byte streams.
- Converting between textual encodings like ASCII, UTF-16, UTF-32 by seeing how they differ in hex.
- Developing a mental model of how bytes, bits, and encoding works under the hood.
So if you‘re ready to step up your binary and hex game, install xxd on your Windows machine and start poking around inside your files! Once you become fluent in hexadecimal, you‘ll gain a deeper understanding and control over the binaries we use every day.


