/** * Provides the given value to the given consumer as a little endian * sequence of the given length. * @param consumer the consumer to provide the bytes to * @param value the value to provide * @param length the number of bytes to use to represent the value * @throws IOException if writing fails */ public static void toLittleEndian(ByteConsumer consumer, final long value, final int length) throws IOException { long num = value; for (int i = 0; i < length; i++) { consumer.accept((int) (num & 0xff)); num >>= 8; } }
/** * Provides the given value to the given consumer as a little endian * sequence of the given length. * @param consumer the consumer to provide the bytes to * @param value the value to provide * @param length the number of bytes to use to represent the value * @throws IOException if writing fails */ public static void toLittleEndian(ByteConsumer consumer, final long value, final int length) throws IOException { long num = value; for (int i = 0; i < length; i++) { consumer.accept((int) (num & 0xff)); num >>= 8; } }