Skip to content

Instantly share code, notes, and snippets.

@atoone
Created January 7, 2019 14:38
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 atoone/9992fd46ba323d2ad80571c86c7a4181 to your computer and use it in GitHub Desktop.
Save atoone/9992fd46ba323d2ad80571c86c7a4181 to your computer and use it in GitHub Desktop.
Quick 'n tidy Hex Dump method
- 0000 0000 0000 0000 0000 0000 0000 0000 ................
- 6425 a19c 0001 0003 0000 0000 5554 0500 d%??........UT..
- 011c 2f38 53 ../8S
private static String doHex(byte[] data, int offset, int length) {
StringBuilder sb = new StringBuilder();
int end = offset+length;
while(offset < end) {
sb.append(" - ");
for(int i=0; i<16; i++) {
if( i+offset >= data.length) {
sb.append(" ");
}
else {
if ((data[i+offset] & 0x0ff) < 16) sb.append("0");
sb.append(Integer.toHexString(data[i + offset] & 0x0FF));
}
if( (i & 0x01) == 0x01 ) sb.append(" ");
}
for(int i=0; i<16; i++) {
if( i+offset >= data.length) {
sb.append(" ");
}
else if( (data[i+offset] & 0x0ff) < 32 ) {
sb.append(".");
}
else if( (data[i+offset] & 0x0ff) >= 127 ) {
sb.append("?");
}
else {
sb.append((char)data[i+offset]);
}
}
sb.append("\n");
offset += 16;
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment