We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 227f7e2 commit 5147fadCopy full SHA for 5147fad
utilcode/src/main/java/com/blankj/utilcode/utils/ConvertUtils.java
@@ -65,9 +65,12 @@ public static String bytes2HexString(byte[] bytes) {
65
* @return 字节数组
66
*/
67
public static byte[] hexString2Bytes(String hexString) {
68
- int len = hexString.length() + 1;
69
- String evenHex = len % 2 != 0 ? hexString : ("0" + hexString);
70
- char[] hexBytes = evenHex.toUpperCase().toCharArray();
+ int len = hexString.length();
+ if(len % 2 !=0){
+ hexString = "0" + hexString;
71
+ len = len + 1;
72
+ }
73
+ char[] hexBytes = hexString.toUpperCase().toCharArray();
74
byte[] ret = new byte[len >> 1];
75
for (int i = 0; i < len; i += 2) {
76
ret[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));
0 commit comments