Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created May 28, 2014 14:56
Show Gist options
  • Save wjlafrance/a84fb7efa523f33477c2 to your computer and use it in GitHub Desktop.
Save wjlafrance/a84fb7efa523f33477c2 to your computer and use it in GitHub Desktop.
Java debug output
private static void debugOutput(byte[] bytes) {
for (int i = 0; i < bytes.length; i += 16) {
for (int j = i; j < (i + 16); j++) {
if (j < bytes.length) {
System.out.format("%02x ", bytes[j]);
} else {
System.out.print(" ");
}
}
System.out.print(" ");
for (int j = i; j < (i + 16); j++) {
if (j < bytes.length) {
char c = (char) bytes[j];
if (Character.isAlphabetic(c) || Character.isDigit(c)) {
System.out.format("%s", Character.valueOf(c).toString());
} else {
System.out.print(".");
}
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment