@Test public void testBigIntToHexStringWithZeroPadded() { String[][] example = new String[][]{ new String[]{ "00010101", "65793", "8" }, new String[]{ "010101", "65793", "6" } }; for (String[] test : example) { assertEquals(test[0], NumericUtil.bigIntegerToHexWithZeroPadded(new BigInteger(test[1]), Integer.parseInt(test[2]))); } }
public static String bigIntegerToHexWithZeroPadded(BigInteger value, int size) { String result = bigIntegerToHex(value); int length = result.length(); if (length > size) { throw new UnsupportedOperationException( "Value " + result + "is larger then length " + size); } else if (value.signum() < 0) { throw new UnsupportedOperationException("Value cannot be negative"); } if (length < size) { result = Strings.repeat("0", size - length) + result; } return result; }
NumericUtil { public static String bigIntegerToHexWithZeroPadded(BigInteger value, int size) { String result = bigIntegerToHex(value); int length = result.length(); if (length > size) { throw new UnsupportedOperationException( "Value " + result + "is larger then length " + size); } else if (value.signum() < 0) { throw new UnsupportedOperationException("Value cannot be negative"); } if (length < size) { result = Strings.repeat("0", size - length) + result; } return result; } }
NumericUtil { public static String bigIntegerToHexWithZeroPadded(BigInteger value, int size) { String result = bigIntegerToHex(value); int length = result.length(); if (length > size) { throw new UnsupportedOperationException( "Value " + result + "is larger then length " + size); } else if (value.signum() < 0) { throw new UnsupportedOperationException("Value cannot be negative"); } if (length < size) { result = Strings.repeat("0", size - length) + result; } return result; }  }
NumericUtil { public static String bigIntegerToHexWithZeroPadded(BigInteger value, int size) { String result = bigIntegerToHex(value); int length = result.length(); if (length > size) { throw new UnsupportedOperationException( "Value " + result + "is larger then length " + size); } else if (value.signum() < 0) { throw new UnsupportedOperationException("Value cannot be negative"); } if (length < size) { result = Strings.repeat("0", size - length) + result; } return result; }  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 bigIntegerToHexWithZeroPadded(BigInteger value, int size) { String result = bigIntegerToHex(value); int length = result.length(); if (length > size) { throw new UnsupportedOperationException( "Value " + result + "is larger then length " + size); } else if (value.signum() < 0) { throw new UnsupportedOperationException("Value cannot be negative"); } if (length < size) { result = Strings.repeat("0", size - length) + result; } return result; }  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);  }