Skip to content

Instantly share code, notes, and snippets.

@erfanegtfi
Created April 13, 2018 12:23
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 erfanegtfi/a778dbf5d722dc9e271612c57b076de5 to your computer and use it in GitHub Desktop.
Save erfanegtfi/a778dbf5d722dc9e271612c57b076de5 to your computer and use it in GitHub Desktop.
convert To Hex String
public static String convertToHexString(byte[] data) {
StringBuilder buf = new StringBuilder();
for (byte b : data) {
int halfbyte = (b >>> 4) & 15;
int two_halfs = 0;
while (true) {
char c = (halfbyte < 0 || halfbyte > 9) ? (char) ((halfbyte - 10) + 97) : (char) (halfbyte + 48);
buf.append(c);
halfbyte = b & 15;
int two_halfs2 = two_halfs + 1;
if (two_halfs >= 1) {
break;
}
two_halfs = two_halfs2;
}
}
return buf.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment