将十六进制的字符串转换成字节数组 @param hexString 字符串 @return 字节
(String hexString)
| 62 | * @return 字节 |
| 63 | */ |
| 64 | public static byte[] hexStrToByteArrs(String hexString) /* throws NullPointerException */ { |
| 65 | if (TextUtils.isEmpty(hexString)) { |
| 66 | throw new NullPointerException("字符串为空"); |
| 67 | } |
| 68 | hexString = hexString.replaceAll(" ", ""); |
| 69 | int len = hexString.length(); |
| 70 | int index = 0; |
| 71 | byte[] bytes = new byte[len / 2]; |
| 72 | while (index < len) { |
| 73 | String sub = hexString.substring(index, index + 2); |
| 74 | bytes[index / 2] = (byte) Integer.parseInt(sub, 16); |
| 75 | index += 2; |
| 76 | } |
| 77 | return bytes; |
| 78 | } |
| 79 | } |