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/c1e2b60826a17b939aae81db5de877da to your computer and use it in GitHub Desktop.
Save erfanegtfi/c1e2b60826a17b939aae81db5de877da to your computer and use it in GitHub Desktop.
convert hexString To Byte Array
public static byte[] convertToByteArray(String hexString) {
int len = hexString.length();
byte[] data = new byte[(len / 2)];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16));
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment