Created
November 8, 2017 04:04
-
-
Save hpcslag/bd0c4b0e9e897c5f0f058ef151d0785e to your computer and use it in GitHub Desktop.
Put byte arrays to hex string decoder.
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 bytesToHex(byte[] bytes) { | |
char[] hexChars = new char[bytes.length * 2]; | |
for ( int j = 0; j < bytes.length; j++ ) { | |
int v = bytes[j] & 0xFF; | |
hexChars[j * 2] = hexArray[v >>> 4]; | |
hexChars[j * 2 + 1] = hexArray[v & 0x0F]; | |
} | |
return new String(hexChars); | |
} | |
//examples: | |
// (byte)-112, (byte)0, (byte)1 -> 0x90, 0x00, 0x01 | |
System.out.println(bytesToHex(new byte[]{-112,0,1})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment