Java Utililty Methods Byte Array to Long

List of utility methods to do Byte Array to Long

Description

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

Method

longbytesToLong(byte[] b)
bytes To Long
if (b.length < 8) {
    throw new IllegalArgumentException("Byte array should contain at least 8 bytes");
long l = 0;
for (int i = 0; i < 8; i++) {
    l += (getUnsignedByte(b[i]) << (8 * i));
return l;
...
longbytesToLong(byte[] bs)
bytes To Long
long rst = 0;
for (int n = 0; n < bs.length; n++) {
    long s = (long) bs[n] >= 0 ? bs[n] : 256 + bs[n];
    rst |= s << (n * 8);
return rst;
longbytesToLong(byte[] buf, int offset, int length, boolean asc)
bytes To Long
if (buf == null) {
    throw new IllegalArgumentException("byte array is null!");
if (length > 8) {
    throw new IllegalArgumentException("byte array size > 8 !");
long l = 0;
if (asc) {
...
longbytesToLong(byte[] bytes)
Convert byte array to original long value.
long l = 0;
for (int i = 0; i < 0 + 8; i++) {
    l <<= 8;
    l ^= bytes[i] & 0xFF;
return l;
longbytesToLong(byte[] bytes)
Converts an array of bytes into a long Byte order: big endian
return (((long) bytes[0] << 56) + ((long) (bytes[1] & BYTESIZE) << 48)
        + ((long) (bytes[2] & BYTESIZE) << 40) + ((long) (bytes[3] & BYTESIZE) << 32)
        + ((long) (bytes[4] & BYTESIZE) << 24) + ((bytes[5] & BYTESIZE) << 16)
        + ((bytes[6] & BYTESIZE) << 8) + ((bytes[7] & BYTESIZE)));
longbytesToLong(byte[] bytes)
bytes To Long
return (0xffL & (long) bytes[0]) | (0xff00L & ((long) bytes[1] << 8))
        | (0xff0000L & ((long) bytes[2] << 16)) | (0xff000000L & ((long) bytes[3] << 24))
        | (0xff00000000L & ((long) bytes[4] << 32)) | (0xff0000000000L & ((long) bytes[5] << 40))
        | (0xff000000000000L & ((long) bytes[6] << 48)) | (0xff00000000000000L & ((long) bytes[7] << 56));
longbytesToLong(byte[] bytes)
bytes To Long
if (bytes == null || bytes.length != 8)
    return 0x0;
return (long) (
(long) (0xff & bytes[0]) << 56 | (long) (0xff & bytes[1]) << 48 | (long) (0xff & bytes[2]) << 40
        | (long) (0xff & bytes[3]) << 32 | (long) (0xff & bytes[4]) << 24 | (long) (0xff & bytes[5]) << 16
        | (long) (0xff & bytes[6]) << 8 | (long) (0xff & bytes[7]) << 0);
longbytesToLong(byte[] bytes)
Converts a byte array to a long number
long n = ((long) (bytes[7])) & 0xFFL;
n |= (((long) bytes[6]) << 8) & 0xFF00L;
n |= (((long) bytes[5]) << 16) & 0xFF0000L;
n |= (((long) bytes[4]) << 24) & 0xFF000000L;
n |= (((long) bytes[3]) << 32) & 0xFF00000000L;
n |= (((long) bytes[2]) << 40) & 0xFF0000000000L;
n |= (((long) bytes[1]) << 48) & 0xFF000000000000L;
n |= (((long) bytes[0]) << 56) & 0xFF00000000000000L;
...
longbytesToLong(byte[] bytes)
bytes To Long
return ((long) bytes[7] << 56) + (((long) bytes[6] & 0xFF) << 48) + (((long) bytes[5] & 0xFF) << 40)
        + (((long) bytes[4] & 0xFF) << 32) + (((long) bytes[3] & 0xFF) << 24)
        + (((long) bytes[2] & 0xFF) << 16) + (((long) bytes[1] & 0xFF) << 8) + ((long) bytes[0] & 0xFF);
longbytesToLong(byte[] bytes, int index)
bytes To Long
return bytesToLong(bytes[index++], bytes[index++], bytes[index++], bytes[index++], bytes[index++],
        bytes[index++], bytes[index++], bytes[index++]);