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[]longToByteArray(long input)
Utility method for converting a long into a byte[]
byte[] output = new byte[8];
longToByteArray(input, output, 0);
return output;
byte[]longToByteArray(long l)
long To Byte Array
byte[] bytes = new byte[8];
longToByteArray(bytes, 0, l);
return bytes;
byte[]longToByteArray(long l)
long To Byte Array
byte[] ba = new byte[8];
for (int i = 0; i < 64; i += 8) {
    ba[i >> 3] = new Long((l & (255L << i)) >> i).byteValue();
return ba;
byte[]longToByteArray(long l)
Converts a long value to a byte array.
byte[] retVal = new byte[8];
for (int i = 0; i < 8; i++) {
    retVal[i] = (byte) l;
    l >>= 8;
return retVal;
intlongToByteArray(long longHi, long longLo, byte[] array, int offset)
long To Byte Array
array[offset++] = (byte) (longHi >>> 56);
array[offset++] = (byte) (longHi >>> 48);
array[offset++] = (byte) (longHi >>> 40);
array[offset++] = (byte) (longHi >>> 32);
array[offset++] = (byte) (longHi >>> 24);
array[offset++] = (byte) (longHi >>> 16);
array[offset++] = (byte) (longHi >>> 8);
array[offset++] = (byte) longHi;
...
byte[]longToByteArray(long number)
long to byte array,byte[8]
byte[] byteArray = new byte[8];
byteArray[7] = (byte) (number & 0xff);
byteArray[6] = (byte) (number >> 8 & 0xff);
byteArray[5] = (byte) (number >> 16 & 0xff);
byteArray[4] = (byte) (number >> 24 & 0xff);
byteArray[3] = (byte) (number >> 32 & 0xff);
byteArray[2] = (byte) (number >> 40 & 0xff);
byteArray[1] = (byte) (number >> 48 & 0xff);
...
voidlongToByteArray(long pSrc, byte[] pDst, int pOffset)
long To Byte Array
pDst[pOffset] = (byte) (pSrc >>> 56);
pDst[pOffset + 1] = (byte) (pSrc >>> 48);
pDst[pOffset + 2] = (byte) (pSrc >>> 40);
pDst[pOffset + 3] = (byte) (pSrc >>> 32);
pDst[pOffset + 4] = (byte) (pSrc >>> 24);
pDst[pOffset + 5] = (byte) (pSrc >>> 16);
pDst[pOffset + 6] = (byte) (pSrc >>> 8);
pDst[pOffset + 7] = (byte) pSrc;
...
byte[]longToByteArray(long source)
Converts the bypassed long value to a byte array.
byte[] result = new byte[8];
for (int i = 0; i < 8; i++) {
    result[i] = new Long((source >> (i << 3)) & 255L).byteValue();
return result;
byte[]longToByteArray(long v)
Converts a long to a byte array of length 8
final byte[] writeBuffer = new byte[8];
writeBuffer[0] = (byte) (v >>> 56);
writeBuffer[1] = (byte) (v >>> 48);
writeBuffer[2] = (byte) (v >>> 40);
writeBuffer[3] = (byte) (v >>> 32);
writeBuffer[4] = (byte) (v >>> 24);
writeBuffer[5] = (byte) (v >>> 16);
writeBuffer[6] = (byte) (v >>> 8);
...
byte[]longToByteArray(long value)
long To Byte Array
return new byte[] { (byte) value, (byte) (value >> 8), (byte) (value >> 16), (byte) (value >> 24),
        (byte) (value >> 32), (byte) (value >> 40), (byte) (value >> 48), (byte) (value >> 56) };