Skip to content

Instantly share code, notes, and snippets.

@klausbrunner
Created December 10, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klausbrunner/e91cb6389dae5df154bb09a62508fce2 to your computer and use it in GitHub Desktop.
Save klausbrunner/e91cb6389dae5df154bb09a62508fce2 to your computer and use it in GitHub Desktop.
Java byte array to hexdump. Format similar to default of hexdump(1).
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment