Java Long to Byte Array longToBytesLE(long value, byte[] buffer, int offset, int length)

Here you can find the source of longToBytesLE(long value, byte[] buffer, int offset, int length)

Description

Converts a long to a little-endian sequence of bytes of the specified length.

License

Open Source License

Parameter

Parameter Description
value the value that is to be converted.
buffer the byte array that is to contain the byte sequence.
offset the offset to buffer at which the sequence is to start.
length the required length of the byte sequence.

Declaration


private static void longToBytesLE(long value, byte[] buffer, int offset, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from  www  .ja  va2 s. com*/
     * Converts a {@code long} to a little-endian sequence of bytes of the specified length.
     *
     * @param value   the value that is to be converted.
     * @param buffer  the byte array that is to contain the byte sequence.
     * @param offset  the offset to {@code buffer} at which the sequence is to start.
     * @param length  the required length of the byte sequence.
     * @since 1.0
     * @see   #longToBytesBE(long, byte[], int, int)
     * @see   #bytesToLongLE(byte[], int, int, boolean)
     */

    private static void longToBytesLE(long value, byte[] buffer, int offset, int length) {
        int endOffset = offset + length;
        for (int i = offset; i < endOffset; ++i) {
            buffer[i] = (byte) value;
            value >>>= 8;
        }
    }
}

Related

  1. longToBytes(long value, byte[] buffer, int offset)
  2. LongToBytes4(long l, byte abyte0[])
  3. LongToBytes8(long l)
  4. LongToBytesLE(final long val)
  5. longToBytesLE(long value, byte[] buffer)
  6. longToBytesPlus8(byte[] p, long v)