Skip to content

Instantly share code, notes, and snippets.

@korayguclu
Created May 3, 2013 12:55
Show Gist options
  • Save korayguclu/5508961 to your computer and use it in GitHub Desktop.
Save korayguclu/5508961 to your computer and use it in GitHub Desktop.
Convert byte to Hex to analyse Encoding problems
public String byteToHex(final byte b) {
// Returns hex String representation of byte b
char hexDigit[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
return new String(array);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment