Skip to content

Commit 5147fad

Browse files
committed
see 10/03 log
1 parent 227f7e2 commit 5147fad

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

utilcode/src/main/java/com/blankj/utilcode/utils/ConvertUtils.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ public static String bytes2HexString(byte[] bytes) {
6565
* @return 字节数组
6666
*/
6767
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();
68+
int len = hexString.length();
69+
if(len % 2 !=0){
70+
hexString = "0" + hexString;
71+
len = len + 1;
72+
}
73+
char[] hexBytes = hexString.toUpperCase().toCharArray();
7174
byte[] ret = new byte[len >> 1];
7275
for (int i = 0; i < len; i += 2) {
7376
ret[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));

0 commit comments

Comments
 (0)