Skip to content

Instantly share code, notes, and snippets.

@Gracker
Created August 11, 2014 08:20
Show Gist options
  • Save Gracker/5a4ab0894e0551863ae6 to your computer and use it in GitHub Desktop.
Save Gracker/5a4ab0894e0551863ae6 to your computer and use it in GitHub Desktop.
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2),
16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment