fix hex bug

This commit is contained in:
Looly
2020-11-20 17:33:36 +08:00
parent 899370a63e
commit 3bd15f999f
3 changed files with 3 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
* 【cron 】 修复CronTimer可能死循环的问题issue#1224@Github * 【cron 】 修复CronTimer可能死循环的问题issue#1224@Github
* 【core 】 修复Calculator.conversion单个数字越界问题issue#1222@Github * 【core 】 修复Calculator.conversion单个数字越界问题issue#1222@Github
* 【poi 】 修复ExcelUtil.getSaxReader使用非MarkSupport流报错问题issue#1225@Github * 【poi 】 修复ExcelUtil.getSaxReader使用非MarkSupport流报错问题issue#1225@Github
* 【core 】 修复HexUtil.format问题issue#I268XT@Gitee
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------

View File

@@ -368,7 +368,7 @@ public class HexUtil {
final int length = hexStr.length(); final int length = hexStr.length();
final StringBuilder builder = StrUtil.builder(length + length / 2); final StringBuilder builder = StrUtil.builder(length + length / 2);
builder.append(hexStr.charAt(0)).append(hexStr.charAt(1)); builder.append(hexStr.charAt(0)).append(hexStr.charAt(1));
for (int i = 1; i < length - 1; i += 2) { for (int i = 2; i < length - 1; i += 2) {
builder.append(CharUtil.SPACE).append(hexStr.charAt(i)).append(hexStr.charAt(i + 1)); builder.append(CharUtil.SPACE).append(hexStr.charAt(i)).append(hexStr.charAt(i + 1));
} }
return builder.toString(); return builder.toString();

View File

@@ -47,6 +47,6 @@ public class HexUtilTest {
public void formatHexTest(){ public void formatHexTest(){
String hex = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d"; String hex = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d";
String formatHex = HexUtil.format(hex); String formatHex = HexUtil.format(hex);
Assert.assertEquals("e8 8c 67 03 80 cb 22 00 95 26 8f 40 22 1f c7 48 fa 6a c3 9d 6e 93 0e 63 c3 0d a6 8b ad 97 f8 85", formatHex); Assert.assertEquals("e8 c6 70 38 0c b2 20 09 52 68 f4 02 21 fc 74 8f a6 ac 39 d6 e9 30 e6 3c 30 da 68 ba d9 7f 88 5d", formatHex);
} }
} }