From fd68a23974cee16944b19851531ce576446df347 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 25 Sep 2020 19:15:14 +0200 Subject: [PATCH] Fixed issue with hex bytesToInts --- build.gradle.kts | 2 +- src/dorkbox/util/Sys.java | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f9b2bf3..83af2a2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,7 +38,7 @@ object Extras { // set for the project const val description = "Utilities for use within Java projects" const val group = "com.dorkbox" - const val version = "1.8.2" + const val version = "1.8.3" // set as project.ext const val name = "Utilities" diff --git a/src/dorkbox/util/Sys.java b/src/dorkbox/util/Sys.java index 288f467..b8d3a75 100644 --- a/src/dorkbox/util/Sys.java +++ b/src/dorkbox/util/Sys.java @@ -347,8 +347,8 @@ class Sys { public static int[] bytesToInts(byte[] bytes, int startPosition, int length) { int[] ints = new int[length]; - - for (int i = startPosition; i < length; i++) { + int endPosition = startPosition + length; + for (int i = startPosition; i < endPosition; i++) { ints[i] = bytes[i] & 0xFF; } @@ -367,11 +367,13 @@ class Sys { public static String bytesToHex(byte[] bytes, int startPosition, int length, boolean padding) { + int endPosition = startPosition + length; + if (padding) { - char[] hexString = new char[3 * length - startPosition]; + char[] hexString = new char[3 * length]; int j = 0; - for (int i = startPosition; i < length; i++) { + for (int i = startPosition; i < endPosition; i++) { hexString[j++] = HEX_CHARS[(bytes[i] & 0xF0) >> 4]; hexString[j++] = HEX_CHARS[bytes[i] & 0x0F]; hexString[j++] = ' '; @@ -380,10 +382,10 @@ class Sys { return new String(hexString); } else { - char[] hexString = new char[2 * length - startPosition]; + char[] hexString = new char[2 * length]; int j = 0; - for (int i = startPosition; i < length; i++) { + for (int i = startPosition; i < endPosition; i++) { hexString[j++] = HEX_CHARS[(bytes[i] & 0xF0) >> 4]; hexString[j++] = HEX_CHARS[bytes[i] & 0x0F]; }