Created
April 13, 2018 12:23
-
-
Save erfanegtfi/a778dbf5d722dc9e271612c57b076de5 to your computer and use it in GitHub Desktop.
convert To Hex String
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
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