Last active
March 7, 2019 17:06
-
-
Save israteneda/3d6be6a435e1aa5e95fc4a6a0192c601 to your computer and use it in GitHub Desktop.
Transform hex string to byte array
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
// Transform hexadecimal String example | |
public byte[] hexStringToByteArray(String s) { | |
byte[] data; | |
int len = s.length(); | |
data = new byte[len / 2]; | |
for (int i = 0; i < len; i += 2) { | |
data[i / 2] = (byte) ((Character.digit( s.charAt( i ), 16 ) << 4) | |
+ Character.digit( s.charAt( i + 1 ), 16 )); | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment