Java Utililty Methods Long to Byte

List of utility methods to do Long to Byte

Description

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

Method

voidlong2byte(byte[] b, long a)
Converts long representation to bytes.
b[0] = (byte) (a & 0xFF);
b[1] = (byte) ((a >>> 8) & 0xFF);
b[2] = (byte) ((a >>> 16) & 0xFF);
b[3] = (byte) ((a >>> 24) & 0xFF);
voidlong2Byte(byte[] bytes, long value, int offset)
long Byte
checkLength(bytes, 8, offset);
bytes[offset + 7] = (byte) ((value & 0xff));
bytes[offset + 6] = (byte) ((value >> 8 * 1) & 0xff);
bytes[offset + 5] = (byte) ((value >> 8 * 2) & 0xff);
bytes[offset + 4] = (byte) ((value >> 8 * 3) & 0xff);
bytes[offset + 3] = (byte) ((value >> 8 * 4) & 0xff);
bytes[offset + 2] = (byte) ((value >> 8 * 5) & 0xff);
bytes[offset + 1] = (byte) ((value >> 8 * 6) & 0xff);
...
byteLong2Byte(long i)
Long Byte
byte o;
try {
    o = new Long(i).byteValue();
} catch (Exception e) {
    o = 0;
return o;
voidlong2byte(long ival, byte b[], int offset)
longbyte
int bits = 64;
for (int i = 0; i < 8; i++) {
    bits -= 8;
    b[offset + i] = (byte) ((ival >> bits) & 0xff);
bytelong2byte(long l)
longbyte
return (byte) (int) (l << 56 >> 56);
byte[]long2byte(long l)
longbyte
byte dest[] = new byte[8];
dest[7] = (byte) (int) (l & 255L);
dest[6] = (byte) (int) (l >>> 8 & 255L);
dest[5] = (byte) (int) (l >>> 16 & 255L);
dest[4] = (byte) (int) (l >>> 24 & 255L);
dest[3] = (byte) (int) (l >>> 32 & 255L);
dest[2] = (byte) (int) (l >>> 40 & 255L);
dest[1] = (byte) (int) (l >>> 48 & 255L);
...
voidlongToByte(byte[] buf, int off, long value)
long To Byte
buf[off + 0] = (byte) (value >>> 56);
buf[off + 1] = (byte) (value >>> 48);
buf[off + 2] = (byte) (value >>> 40);
buf[off + 3] = (byte) (value >>> 32);
buf[off + 4] = (byte) (value >>> 24);
buf[off + 5] = (byte) (value >>> 16);
buf[off + 6] = (byte) (value >>> 8);
buf[off + 7] = (byte) (value >>> 0);
...
BytelongToByte(final long value)
long To Byte
return (byte) value;
byte[]longToByte(long a_value)
long To Byte
byte[] bytes = new byte[8];
for (int i = 1; i <= bytes.length; i++) {
    bytes[8 - i] = new Long(a_value).byteValue();
    a_value = a_value >> 8;
return bytes;
byte[]longToByte(long i)
long To Byte
return numberToByte(i, 8);