@Test public void testBytesToHexString() { Object[][] example = new Object[][] { new Object[] { new byte[]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, "01010101010101010101010101010101010101010101010101010101010101010101010101010101" }, new Object[] { new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, "010101010101010101010101" }, new Object[] { new byte[] { 1,1,1 }, "010101" }, new Object[] { new byte[0], "" }, }; for(Object[] test : example) { assertEquals(test[1], NumericUtil.bytesToHex((byte[])test[0])); } }
public static String bytesToHex(byte[] input) { StringBuilder stringBuilder = new StringBuilder(); if (input.length == 0) { return ""; } for (byte anInput : input) { stringBuilder.append(String.format("%02x", anInput)); } return stringBuilder.toString(); }
NumericUtil { public static String bytesToHex(byte[] input) { StringBuilder stringBuilder = new StringBuilder(); if (input.length == 0) { return ""; } for (byte anInput : input) { stringBuilder.append(String.format("%02x", anInput)); } return stringBuilder.toString(); } }
NumericUtil { public static String bytesToHex(byte[] input) { StringBuilder stringBuilder = new StringBuilder(); if (input.length == 0) { return ""; } for (byte anInput : input) { stringBuilder.append(String.format("%02x", anInput)); } return stringBuilder.toString(); }  }
NumericUtil { public static String bytesToHex(byte[] input) { StringBuilder stringBuilder = new StringBuilder(); if (input.length == 0) { return ""; } for (byte anInput : input) { stringBuilder.append(String.format("%02x", anInput)); } return stringBuilder.toString(); }  static byte[] generateRandomBytes(int size); static boolean isValidHex(String value); static String cleanHexPrefix(String input); static String prependHexPrefix(String input); static BigInteger bytesToBigInteger(byte[] value, int offset, int length); static BigInteger bytesToBigInteger(byte[] value); static BigInteger hexToBigInteger(String hexValue); static String bigIntegerToHex(BigInteger value); static String bigIntegerToHexWithZeroPadded(BigInteger value, int size); static byte[] bigIntegerToBytesWithZeroPadded(BigInteger value, int length); static byte[] hexToBytes(String input); static byte[] hexToBytesLittleEndian(String input); static byte[] reverseBytes(byte[] bytes); static String bytesToHex(byte[] input); static String beBigEndianHex(String hex); static String beLittleEndianHex(String hex); static int bytesToInt(byte[] bytes); static byte[] intToBytes(int intValue); }
NumericUtil { public static String bytesToHex(byte[] input) { StringBuilder stringBuilder = new StringBuilder(); if (input.length == 0) { return ""; } for (byte anInput : input) { stringBuilder.append(String.format("%02x", anInput)); } return stringBuilder.toString(); }  static byte[] generateRandomBytes(int size); static boolean isValidHex(String value); static String cleanHexPrefix(String input); static String prependHexPrefix(String input); static BigInteger bytesToBigInteger(byte[] value, int offset, int length); static BigInteger bytesToBigInteger(byte[] value); static BigInteger hexToBigInteger(String hexValue); static String bigIntegerToHex(BigInteger value); static String bigIntegerToHexWithZeroPadded(BigInteger value, int size); static byte[] bigIntegerToBytesWithZeroPadded(BigInteger value, int length); static byte[] hexToBytes(String input); static byte[] hexToBytesLittleEndian(String input); static byte[] reverseBytes(byte[] bytes); static String bytesToHex(byte[] input); static String beBigEndianHex(String hex); static String beLittleEndianHex(String hex); static int bytesToInt(byte[] bytes); static byte[] intToBytes(int intValue);  }