Skip to content

Instantly share code, notes, and snippets.

@KlausBrunner
KlausBrunner / hexdump.java
Created Dec 10, 2019
Java byte array to hexdump. Format similar to default of hexdump(1).
View hexdump.java
static String hexDump(byte[] bytes) {
Formatter format = new Formatter(new StringBuilder());
for (int j = 0; j < bytes.length; j++) {
if (j % 16 == 0) {
format.format((j > 0 ? "\n" : "") + "%08X ", j);
}
format.format("%02X ", bytes[j]);
}
return format.toString();
}