|
|
@@ -199,7 +199,8 @@ public class HexUtil {
|
|
|
if (StrUtil.isEmpty(hexStr)) {
|
|
|
return null;
|
|
|
}
|
|
|
- hexStr = StrUtil.removeAll(hexStr, ' ');
|
|
|
+
|
|
|
+ hexStr = StrUtil.cleanBlank(hexStr);
|
|
|
return decodeHex(hexStr.toCharArray());
|
|
|
}
|
|
|
|
|
|
@@ -342,17 +343,37 @@ public class HexUtil {
|
|
|
|
|
|
/**
|
|
|
* Hex(16进制)字符串转为BigInteger
|
|
|
+ *
|
|
|
* @param hexStr Hex(16进制字符串)
|
|
|
* @return {@link BigInteger}
|
|
|
* @since 5.2.0
|
|
|
*/
|
|
|
- public static BigInteger toBigInteger(String hexStr){
|
|
|
- if(null == hexStr){
|
|
|
+ public static BigInteger toBigInteger(String hexStr) {
|
|
|
+ if (null == hexStr) {
|
|
|
return null;
|
|
|
}
|
|
|
return new BigInteger(hexStr, 16);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 格式化Hex字符串,结果为每2位加一个空格,类似于:
|
|
|
+ * <pre>
|
|
|
+ * e8 8c 67 03 80 cb 22 00 95 26 8f
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @param hexStr Hex字符串
|
|
|
+ * @return 格式化后的字符串
|
|
|
+ */
|
|
|
+ public static String format(String hexStr) {
|
|
|
+ final int length = hexStr.length();
|
|
|
+ final StringBuilder builder = StrUtil.builder(length + length / 2);
|
|
|
+ builder.append(hexStr.charAt(0)).append(hexStr.charAt(1));
|
|
|
+ for (int i = 1; i < length - 1; i += 2) {
|
|
|
+ builder.append(CharUtil.SPACE).append(hexStr.charAt(i)).append(hexStr.charAt(i + 1));
|
|
|
+ }
|
|
|
+ return builder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
// ---------------------------------------------------------------------------------------- Private method start
|
|
|
|
|
|
/**
|