Java Utililty Methods Long to Byte Array

List of utility methods to do Long to Byte Array

Description

The list of methods to do Long to Byte Array are organized into topic(s).

Method

byte[]long2bytes(long... numbers)
longbytes
byte[] b = new byte[8 * numbers.length];
for (int i = 0; i < numbers.length; i++) {
    byte[] tmp = _long2bytes(numbers[i]);
    for (int j = 0; j < tmp.length; j++) {
        b[i * 8 + j] = tmp[j];
return b;
...
byte[]long2bytesBE(long val, byte[] b, int off)
longbytes BE
b[off] = (byte) (val >>> 56);
b[off + 1] = (byte) (val >>> 48);
b[off + 2] = (byte) (val >>> 40);
b[off + 3] = (byte) (val >>> 32);
b[off + 4] = (byte) (val >>> 24);
b[off + 5] = (byte) (val >>> 16);
b[off + 6] = (byte) (val >>> 8);
b[off + 7] = (byte) val;
...
byte[]longToByteArr(long v)
long To Byte Arr
return new byte[] { (byte) (v >>> 56), (byte) (v >>> 48), (byte) (v >>> 40), (byte) (v >>> 32),
        (byte) (v >>> 24), (byte) (v >>> 16), (byte) (v >>> 8), (byte) (v) };
byte[]longToByteArray(final long l)
Create a byte array from long.
Can be revert with #byteArrayToLong(byte[])
final byte[] array = new byte[8];
array[0] = (byte) ((l >> 56) & 0xFF);
array[1] = (byte) ((l >> 48) & 0xFF);
array[2] = (byte) ((l >> 40) & 0xFF);
array[3] = (byte) ((l >> 32) & 0xFF);
array[4] = (byte) ((l >> 24) & 0xFF);
array[5] = (byte) ((l >> 16) & 0xFF);
array[6] = (byte) ((l >> 8) & 0xFF);
...
voidlongToByteArray(final long v, final byte[] buf, final int offset)
long To Byte Array
buf[offset + 0] = (byte) ((v >> 56) & 0xFF);
buf[offset + 1] = (byte) ((v >> 48) & 0xFF);
buf[offset + 2] = (byte) ((v >> 40) & 0xFF);
buf[offset + 3] = (byte) ((v >> 32) & 0xFF);
buf[offset + 4] = (byte) ((v >> 24) & 0xFF);
buf[offset + 5] = (byte) ((v >> 16) & 0xFF);
buf[offset + 6] = (byte) ((v >> 8) & 0xFF);
buf[offset + 7] = (byte) ((v >> 0) & 0xFF);
...
voidlongToByteArray(final long val, final byte[] buf, final int offset)
Copies the byte representation of a long into a byte array starting at the given offset
buf[offset + 0] = (byte) ((val >> 56));
buf[offset + 1] = (byte) ((val >> 48));
buf[offset + 2] = (byte) ((val >> 40));
buf[offset + 3] = (byte) ((val >> 32));
buf[offset + 4] = (byte) ((val >> 24));
buf[offset + 5] = (byte) ((val >> 16));
buf[offset + 6] = (byte) ((val >> 8));
buf[offset + 7] = (byte) ((val) >> 0);
...
byte[]longToByteArray(final long value, final int size)
Classname / Method Name : CalculationHelper/longToByteArray()
final byte[] b = new byte[size];
for (int i = 0; i < size; i++) {
    final int offset = (b.length - 1 - i) * 8;
    b[i] = (byte) ((value >> offset) & 0xFF);
return b;
voidlongToByteArray(long a, byte[] buf)
Converts an long to a byte array with a length of 8.
buf[0] = (byte) ((a >> 56) & 0xFF);
buf[1] = (byte) ((a >> 48) & 0xFF);
buf[2] = (byte) ((a >> 40) & 0xFF);
buf[3] = (byte) ((a >> 32) & 0xFF);
buf[4] = (byte) ((a >> 24) & 0xFF);
buf[5] = (byte) ((a >> 16) & 0xFF);
buf[6] = (byte) ((a >> 8) & 0xFF);
buf[7] = (byte) (a & 0xFF);
...
byte[]longToByteArray(long i64)
long To Byte Array
i64out[0] = (byte) (0xff & (i64 >> 56));
i64out[1] = (byte) (0xff & (i64 >> 48));
i64out[2] = (byte) (0xff & (i64 >> 40));
i64out[3] = (byte) (0xff & (i64 >> 32));
i64out[4] = (byte) (0xff & (i64 >> 24));
i64out[5] = (byte) (0xff & (i64 >> 16));
i64out[6] = (byte) (0xff & (i64 >> 8));
i64out[7] = (byte) (0xff & (i64));
...
byte[]longToByteArray(long in)
long To Byte Array
byte[] out = new byte[8];
for (int index = 7; index >= 0; index--) {
    out[index] = (byte) in;
    in >>= 8;
return out;