Skip to content

Instantly share code, notes, and snippets.

@israteneda
Last active March 7, 2019 17:06
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 israteneda/3d6be6a435e1aa5e95fc4a6a0192c601 to your computer and use it in GitHub Desktop.
Save israteneda/3d6be6a435e1aa5e95fc4a6a0192c601 to your computer and use it in GitHub Desktop.
Transform hex string to byte array
// 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