I’ve been tinkering on a 6502 project during the evenings spread over the last 3 months (via the excellent [Ben Eater](https://www.youtube.com/watch?v=LnzuMJLZRdU\&list=PLowKtXNTBypFbtuVMUVXNR0z1mu7dp7eH) series) and in doing so I’ve started to build up a series of tools I use with binary.

(This post is probably only useful for future Remy)

[I’ve published 38 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.](https://training.leftlogic.com/buy/terminal/cli2?coupon=BLOG\&utm_source=blog\&utm_medium=banner\&utm_campaign=remysharp-discount)

I should add that I’m not sure how much of this will work on different systems and availability of tools, but I’ll link where possible.

hexdump[](#hexdump)

[hexdump](https://www.mankier.com/1/hexdump) - usually with hexdump -C file.bin to view hex and ascii output. Also compresses repeating patterns seen below where the line is simply *.

Really simple to use tool for viewing source hex on the command line.

$ hexdump -C rom.bin
00000000  a9 ff 8d 02 60 a9 55 8d  00 60 a9 aa 8d 00 60 4c  |....`.U..`....`L|
00000010  05 80 ea ea ea ea ea ea  ea ea ea ea ea ea ea ea  |................|
00000020  ea ea ea ea ea ea ea ea  ea ea ea ea ea ea ea ea  |................|
*
00007ff0  ea ea ea ea ea ea ea ea  ea ea ea ea 00 80 ea ea  |................|
00008000

xxd[](#xxd)

[xxd](https://www.mankier.com/1/xxd) can dump hex from binary, but also convert hex to binary.

This is used for dumping the entire hex content out. It also has a revert feature that lets me generate binary files from strings of hex. I’ve been doing a bit of work around unpacking old file formats, and generating snippet of binary data is useful.

Below you can see my generating a binary snippet for a ZX Spectrum+ .bas file header. The first column needs to be the offset (0 in this case).

$ echo "0 504c 5553 3344 4f53 1a01 00e7 0000 00" | xxd -r | hexdump -C
00000000  50 4c 55 53 33 44 4f 53  1a 01 00 e7 00 00 00     |PLUS3DOS.......|
0000000f

I could capture this output using … | xxd -r > out.bin and then process the binary elsewhere.

diffing binary / diffing hex[](#diffing-binary—​diffing-hex)

Using xxd above, I can combine diff tools to identify changes between binary (typically where I’ve got a typo and generated a slightly different file).

$ diff -u <(xxd -c 32 a.bin) <(xxd -c 32 b.bin) | diff-so-fancy

I’m adding [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy/) into the mix to clearly highlight the changes in the file (the diff -u flag is needed to make this work properly).

![Visual hex diff](/images/hex-diff.png)

In the diff above I can clearly see that the first block starts to match, but the does not.

Honourable mentions[](#honourable-mentions)

Published 2-Mar 2020 under #code. [Edit this post](https://github.com/remy/remysharp.com/blob/main/public/blog/binary-tools.md)

👍 8 likes

[![Kevin Vanderbeken](/images/no-user.svg "Kevin Vanderbeken")](![Robot Zero(/images/no-user.svg "Robot Zero")](![Yuriy Markov(/images/no-user.svg "Yuriy Markov")](![Беру и делаю(/images/no-user.svg "Беру и делаю")](![👾 Attila Gonda(/images/no-user.svg "👾 Attila Gonda")](![ВиК Перник ЕООД(/images/no-user.svg "ВиК Перник ЕООД")](![Djordje Cupic(/images/no-user.svg "Djordje Cupic")](![Thorsten Ball(/images/no-user.svg "Thorsten Ball")](https://twitter.com/thorstenball)

Comments

Lock Thread

Login

Add Comment[M ↓   Markdown]()

[Commento](https://commento.io)