/** * @throws IllegalArgumentException if the given string is invalid hex */ public static byte[] parseHex(String hex) { int length = hex.length(); if (length % 2 != 0) { throw new IllegalArgumentException("Illegal string length: " + length); } int bytesLength = length / 2; byte[] bytes = new byte[bytesLength]; int idxChar = 0; for (int i = 0; i < bytesLength; i++) { int value = parseHexDigit(hex.charAt(idxChar++)) << 4; value |= parseHexDigit(hex.charAt(idxChar++)); bytes[i] = (byte) value; } return bytes; }
/** * @throws IllegalArgumentException if the given string is invalid hex */ public static byte[] parseHex(String hex) { int length = hex.length(); if (length % 2 != 0) { throw new IllegalArgumentException("Illegal string length: " + length); } int bytesLength = length / 2; byte[] bytes = new byte[bytesLength]; int idxChar = 0; for (int i = 0; i < bytesLength; i++) { int value = parseHexDigit(hex.charAt(idxChar++)) << 4; value |= parseHexDigit(hex.charAt(idxChar++)); bytes[i] = (byte) value; } return bytes; }
/** * @throws IllegalArgumentException if the given string is invalid hex */ public static byte[] parseHex(String hex) { int length = hex.length(); if (length % 2 != 0) { throw new IllegalArgumentException("Illegal string length: " + length); } int bytesLength = length / 2; byte[] bytes = new byte[bytesLength]; int idxChar = 0; for (int i = 0; i < bytesLength; i++) { int value = parseHexDigit(hex.charAt(idxChar++)) << 4; value |= parseHexDigit(hex.charAt(idxChar++)); bytes[i] = (byte) value; } return bytes; }
/** * @throws IllegalArgumentException if the given string is invalid hex */ public static byte[] parseHex(String hex) { int length = hex.length(); if (length % 2 != 0) { throw new IllegalArgumentException("Illegal string length: " + length); } int bytesLength = length / 2; byte[] bytes = new byte[bytesLength]; int idxChar = 0; for (int i = 0; i < bytesLength; i++) { int value = parseHexDigit(hex.charAt(idxChar++)) << 4; value |= parseHexDigit(hex.charAt(idxChar++)); bytes[i] = (byte) value; } return bytes; }