/** * Convert an int array into a byte array. * * @param input the int array * @return the converted array */ public static byte[] toByteArray(final int[] input) { byte[] result = new byte[input.length << 2]; for (int i = 0; i < input.length; i++) { I2OSP(input[i], result, i << 2); } return result; }
/** * @param input an int arary * @return the int array as hex string */ public static String toHexString(int[] input) { return ByteUtils.toHexString(BigEndianConversions.toByteArray(input)); }
/** * Convert a byte array into an int array. * * @param input the byte array * @return the converted array */ public static int[] toIntArray(byte[] input) { final int intLen = (input.length + 3) / 4; final int lastLen = input.length & 0x03; int[] result = new int[intLen]; int index = 0; for (int i = 0; i <= intLen - 2; i++, index += 4) { result[i] = OS2IP(input, index); } if (lastLen != 0) { result[intLen - 1] = OS2IP(input, index, lastLen); } else { result[intLen - 1] = OS2IP(input, index); } return result; }
/** * @param input an int arary * @return the int array as hex string */ public static String toHexString(int[] input) { return ByteUtils.toHexString(BigEndianConversions.toByteArray(input)); }
/** * Convert a byte array into an int array. * * @param input the byte array * @return the converted array */ public static int[] toIntArray(byte[] input) { final int intLen = (input.length + 3) / 4; final int lastLen = input.length & 0x03; int[] result = new int[intLen]; int index = 0; for (int i = 0; i <= intLen - 2; i++, index += 4) { result[i] = OS2IP(input, index); } if (lastLen != 0) { result[intLen - 1] = OS2IP(input, index, lastLen); } else { result[intLen - 1] = OS2IP(input, index); } return result; }
/** * Convert an int array into a byte array. * * @param input the int array * @return the converted array */ public static byte[] toByteArray(final int[] input) { byte[] result = new byte[input.length << 2]; for (int i = 0; i < input.length; i++) { I2OSP(input[i], result, i << 2); } return result; }
/** * Convert an int array into a byte array of the specified length. No length * checking is performed (i.e., if the last integer cannot be encoded into * <tt>length % 4</tt> octets, it is truncated). * * @param input the int array * @param length the length of the converted array * @return the converted array */ public static byte[] toByteArray(final int[] input, int length) { final int intLen = input.length; byte[] result = new byte[length]; int index = 0; for (int i = 0; i <= intLen - 2; i++, index += 4) { I2OSP(input[i], result, index); } I2OSP(input[intLen - 1], result, index, length - index); return result; }
/** * Convert an int array into a byte array of the specified length. No length * checking is performed (i.e., if the last integer cannot be encoded into * <tt>length % 4</tt> octets, it is truncated). * * @param input the int array * @param length the length of the converted array * @return the converted array */ public static byte[] toByteArray(final int[] input, int length) { final int intLen = input.length; byte[] result = new byte[length]; int index = 0; for (int i = 0; i <= intLen - 2; i++, index += 4) { I2OSP(input[i], result, index); } I2OSP(input[intLen - 1], result, index, length - index); return result; }