Browse Source

fix hex bug

Looly 5 years ago
parent
commit
3bd15f999f

+ 1 - 0
CHANGELOG.md

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

+ 1 - 1
hutool-core/src/main/java/cn/hutool/core/util/HexUtil.java

@@ -368,7 +368,7 @@ public class HexUtil {
 		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) {
+		for (int i = 2; i < length - 1; i += 2) {
 			builder.append(CharUtil.SPACE).append(hexStr.charAt(i)).append(hexStr.charAt(i + 1));
 		}
 		return builder.toString();

+ 1 - 1
hutool-core/src/test/java/cn/hutool/core/util/HexUtilTest.java

@@ -47,6 +47,6 @@ public class HexUtilTest {
 	public void formatHexTest(){
 		String hex = "e8c670380cb220095268f40221fc748fa6ac39d6e930e63c30da68bad97f885d";
 		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);
 	}
 }