(String inHex)
| 402 | |
| 403 | //hex 转字节数组 |
| 404 | public static byte[] hexToByteArray(String inHex){ |
| 405 | int hexlen = inHex.length(); |
| 406 | byte[] result; |
| 407 | if (hexlen % 2 == 1){ |
| 408 | //奇数 |
| 409 | hexlen++; |
| 410 | result = new byte[(hexlen/2)]; |
| 411 | inHex="0"+inHex; |
| 412 | }else { |
| 413 | //偶数 |
| 414 | result = new byte[(hexlen/2)]; |
| 415 | } |
| 416 | int j=0; |
| 417 | for (int i = 0; i < hexlen; i+=2){ |
| 418 | result[j]=hexToByte(inHex.substring(i,i+2)); |
| 419 | j++; |
| 420 | } |
| 421 | return result; |
| 422 | } |
| 423 | |
| 424 | public static byte hexToByte(String inHex){ |
| 425 | return (byte)Integer.parseInt(inHex,16); |
no test coverage detected