Created
January 7, 2019 14:38
-
-
Save atoone/9992fd46ba323d2ad80571c86c7a4181 to your computer and use it in GitHub Desktop.
Quick 'n tidy Hex Dump method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 0000 0000 0000 0000 0000 0000 0000 0000 ................ | |
- 6425 a19c 0001 0003 0000 0000 5554 0500 d%??........UT.. | |
- 011c 2f38 53 ../8S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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