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(final byte[] bytes)
Reads a big-endian 8-byte long from an offset in the given array.
return (bytes[0] & 0xFFL) << 56 | (bytes[1] & 0xFFL) << 48 | (bytes[2] & 0xFFL) << 40
        | (bytes[3] & 0xFFL) << 32 | (bytes[4] & 0xFFL) << 24 | (bytes[5] & 0xFFL) << 16
        | (bytes[6] & 0xFFL) << 8 | (bytes[7] & 0xFFL) << 0;
longbytesToLong(final byte[] bytes)
bytes To Long
long result = 0;
for (int i = 0; i < bytes.length; i++) {
    int temp = (int) bytes[i];
    if (temp < 0) {
        temp = 0x100 + temp;
    result += temp << (8 * (bytes.length - 1 - i));
return result;
longbytesToLong(final byte[] data, final int offset)
Undo #longToBytes(long) and reconstruct the long value.
if (data == null) {
    return 0x0;
return (long) (0xff & data[offset + 0]) << 56 | (long) (0xff & data[offset + 1]) << 48
        | (long) (0xff & data[offset + 2]) << 40 | (long) (0xff & data[offset + 3]) << 32
        | (long) (0xff & data[offset + 4]) << 24 | (long) (0xff & data[offset + 5]) << 16
        | (long) (0xff & data[offset + 6]) << 8 | (long) (0xff & data[offset + 7]);
longbytesToLongLE(byte[] bytes, int off)
bytes To Long LE
return ((long) bytes[off + 7] << 56) + ((long) (bytes[off + 6] & 255) << 48)
        + ((long) (bytes[off + 5] & 255) << 40) + ((long) (bytes[off + 4] & 255) << 32)
        + ((long) (bytes[off + 3] & 255) << 24) + ((bytes[off + 2] & 255) << 16)
        + ((bytes[off + 1] & 255) << 8) + (bytes[off] & 255);
longbyteToLong(byte[] b)
byte To Long
long s = 0;
long s0 = b[0] & 0xff;
long s1 = b[1] & 0xff;
long s2 = b[2] & 0xff;
long s3 = b[3] & 0xff;
long s4 = b[4] & 0xff;
long s5 = b[5] & 0xff;
long s6 = b[6] & 0xff;
...
longbyteToLong(byte[] b)
byte To Long
if (b.length == 1) {
    return b[0] & 0xFF;
} else if (b.length == 2) {
    return (long) ((b[0] & 0xFF) << 8) | (long) (b[1] & 0xFF);
} else if (b.length == 3) {
    return (long) ((b[0] & 0xFF) << 16) | (long) ((b[1] & 0xFF) << 8) | (long) (b[2] & 0xFF);
} else if (b.length == 4) {
    return (long) ((b[0] & 0xFF) << 24) | (long) ((b[1] & 0xFF) << 16) | (long) ((b[2] & 0xFF) << 8)
...
longbyteToLong(byte[] buf, int off)
byte To Long
return (((long) buf[off + 0] << 56) + ((long) (buf[off + 1] & 255) << 48)
        + ((long) (buf[off + 2] & 255) << 40) + ((long) (buf[off + 3] & 255) << 32)
        + ((long) (buf[off + 4] & 255) << 24) + ((buf[off + 5] & 255) << 16) + ((buf[off + 6] & 255) << 8)
        + ((buf[off + 7] & 255) << 0));
longbyteToLong(byte[] byteArray)
byte To Long
return (((long) (byteArray[0]) & 0xFF) << 56) | (((long) (byteArray[1]) & 0xFF) << 48)
        | (((long) (byteArray[2]) & 0xFF) << 40) | (((long) (byteArray[3]) & 0xFF) << 32)
        | (((long) (byteArray[4]) & 0xFF) << 24) | (((long) (byteArray[5]) & 0xFF) << 16)
        | (((long) (byteArray[6]) & 0xFF) << 8) | ((long) (byteArray[7]) & 0xFF);
longbyteToLong(byte[] bytesToConvert)
Converts a byte to long variable.
final StringBuilder builder = new StringBuilder();
for (byte eachByte : bytesToConvert) {
    builder.append(String.format("%02x", eachByte));
long num = Long.parseLong(builder.toString(), 16);
return num;
longbyteToLong(byte[] i_Value)
byte To Long
if (i_Value.length >= 8) {
    return (((long) (byteToInt(substr(i_Value, 0, 4)))) << 32)
            + ((byteToInt(substr(i_Value, 4, 4)) & 0xFFFFFFFFL));
} else if (i_Value.length <= 4) {
    return (byteToInt(substr(i_Value, 4, 4)) & 0xFFFFFFFFL);
} else if (i_Value.length > 4) {
    return (((long) (byteToInt(substr(i_Value, 0, i_Value.length - 4)))) << 32)
            + ((byteToInt(substr(i_Value, i_Value.length - 4, 4)) & 0xFFFFFFFFL));
...