Fixed bug when converting hex to bytes
This commit is contained in:
parent
3bc287848e
commit
2b0002d7cf
@ -15,7 +15,13 @@ public class Utils {
|
|||||||
return hexString.toString();
|
return hexString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte[] stringToBytes(String hexString) {
|
static byte[] stringToBytes(String s) {
|
||||||
return new BigInteger(hexString, 16).toByteArray();
|
int len = s.length();
|
||||||
|
byte[] data = new byte[len / 2];
|
||||||
|
for (int i = 0; i < len; i += 2) {
|
||||||
|
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||||
|
+ Character.digit(s.charAt(i+1), 16));
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user