Created
August 11, 2014 08:20
-
-
Save Gracker/5a4ab0894e0551863ae6 to your computer and use it in GitHub Desktop.
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
/** | |
* 将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