I work a lot with network and serial communications software, so it is often necessary for me to have code to display or log hex dumps of data packets.
Every time I do this, I write yet another hex-dump routine from scratch. I'm about to do so again, but figured I'd ask here: Is there any good free hex dump code for C++ out there somewhere?
Features I'd like:
- N bytes per line (where N is somehow configurable)
- optional ASCII/UTF8 dump alongside the hex
- configurable indentation, per-line prefixes, per-line suffixes, etc.
- minimal dependencies (ideally, I'd like the code to all be in a header file, or be a snippet I can just paste in)
Edit: Clarification: I am looking for code that I can easily drop in to my own programs to write to stderr, stdout, log files, or other such output streams. I'm not looking for a command-line hex dump utility.
xxd is the 'standard' hex dump util and looks like it should solve your problems