Skip to content

Commit c8f4270

Browse files
committed
Minor refactoring in hex decoder
1 parent 8a449bd commit c8f4270

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main/java/at/favre/lib/bytes/BinaryToTextEncoding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ public String encode(byte[] byteArray, ByteOrder byteOrder) {
104104

105105
@Override
106106
public byte[] decode(CharSequence hexString) {
107-
Objects.requireNonNull(hexString, "hex input must not be null");
108-
if (hexString.length() % 2 != 0)
107+
if (Objects.requireNonNull(hexString, "hex input must not be null").length() % 2 != 0)
109108
throw new IllegalArgumentException("invalid hex string, must be mod 2 == 0");
110109

111110
int start;
112-
if (hexString.toString().startsWith("0x")) {
111+
if (hexString.length() > 2 &&
112+
hexString.charAt(0) == '0' && hexString.charAt(1) == 'x') {
113113
start = 2;
114114
} else {
115115
start = 0;

0 commit comments

Comments
 (0)