Five Line Hex Dump
I work with message formats a lot. Being able to conjure up a hex dump on the spot is an invaluable skill. You’d think that you should have a library function for this; however, there’s often problems – it’s not in the path for this project, the built-in one doesn’t work on this JVM, the link settings aren’t right to use it, etc. So I’ve typed this hundreds of times:
for (int i = 0; i < data.length; ++i) { if (i%16==0) System.err.println(); System.err.printf("%02x ",data[i]); } System.err.println();
The C and C++ equivalents are almost identical.
Leave a comment
| Trackback
