@Test(expected = NullPointerException.class) public void fromHex_null() { byte[] bytes = ByteArrayUtil.fromHex(null); }
public static byte[] fromHex(String hex) { hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase(); if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Odd numbered hex array"); } byte[] byteArray = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { byteArray[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return byteArray; }
ByteArrayUtil { public static byte[] fromHex(String hex) { hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase(); if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Odd numbered hex array"); } byte[] byteArray = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { byteArray[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return byteArray; } }
ByteArrayUtil { public static byte[] fromHex(String hex) { hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase(); if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Odd numbered hex array"); } byte[] byteArray = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { byteArray[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return byteArray; } private  ByteArrayUtil(); }
ByteArrayUtil { public static byte[] fromHex(String hex) { hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase(); if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Odd numbered hex array"); } byte[] byteArray = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { byteArray[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return byteArray; } private  ByteArrayUtil(); static byte[] fromHex(String hex); static String toHex(byte[] byteArray); static int twoBytesToInt(byte[] bytes, int offset); static int twoBytesSignedToInt(byte[] bytes, int offset); static int threeBytesToInt(byte[] bytes, int offset); static int threeBytesSignedToInt(byte[] bytes, int offset); static int fourBytesToInt(byte[] bytes, int offset); }
ByteArrayUtil { public static byte[] fromHex(String hex) { hex = HEX_IGNORED_CHARS.matcher(hex).replaceAll("").toUpperCase(); if (hex.length() % 2 != 0) { throw new IllegalArgumentException("Odd numbered hex array"); } byte[] byteArray = new byte[hex.length() / 2]; for (int i = 0; i < hex.length(); i += 2) { byteArray[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) + Character.digit(hex.charAt(i + 1), 16)); } return byteArray; } private  ByteArrayUtil(); static byte[] fromHex(String hex); static String toHex(byte[] byteArray); static int twoBytesToInt(byte[] bytes, int offset); static int twoBytesSignedToInt(byte[] bytes, int offset); static int threeBytesToInt(byte[] bytes, int offset); static int threeBytesSignedToInt(byte[] bytes, int offset); static int fourBytesToInt(byte[] bytes, int offset);  }