Java Utililty Methods Long Number Create

List of utility methods to do Long Number Create

Description

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

Method

longtoLong(byte[] arr)
to Long
int high = (arr[0] << 24) | ((arr[1] & 0xff) << 16) | ((arr[2] & 0xff) << 8) | (arr[3] & 0xff);
int low = (arr[4] << 24) | ((arr[5] & 0xff) << 16) | ((arr[6] & 0xff) << 8) | (arr[7] & 0xff);
return (((long) high) << 32) | (low & 0x0ffffffffL);
longtoLong(byte[] array, int offset)
to Long
long value = 0;
for (int i = offset; i < offset + 8; i++) {
    value <<= 8;
    value ^= (long) array[i] & 0xFF;
return value;
longtoLong(byte[] b)
to Long
return ((((long) b[7]) & 0xFF) | ((((long) b[6]) & 0xFF) << 8) | ((((long) b[5]) & 0xFF) << 16)
        | ((((long) b[4]) & 0xFF) << 24) | ((((long) b[3]) & 0xFF) << 32) | ((((long) b[2]) & 0xFF) << 40)
        | ((((long) b[1]) & 0xFF) << 48) | ((((long) b[0]) & 0xFF) << 56));
longtoLong(byte[] b)
Converts a byte array of 1-8 bytes to a long.
if ((b.length < 1) || (b.length > 8)) {
    throw new IllegalArgumentException("Array of size " + b.length + " cannot be converted to long.");
long result = 0L;
for (int i = 0; i < b.length; i++) {
    result = ((0xFFL & b[i]) << ((b.length - i - 1) * 8)) | result;
return result;
...
longtoLong(byte[] b)
Build a long from first 8 bytes of the array.
if (b.length != 8) {
    throw new IllegalArgumentException();
return ((long) b[7] & 0xFF) + (((long) b[6] & 0xFF) << 8) + (((long) b[5] & 0xFF) << 16)
        + (((long) b[4] & 0xFF) << 24) + (((long) b[3] & 0xFF) << 32) + (((long) b[2] & 0xFF) << 40)
        + (((long) b[1] & 0xFF) << 48) + (((long) b[0] & 0xFF) << 56);
longtoLong(byte[] b)
to Long
long MASK = 0xFF;
long result = 0;
result = b[7] & MASK;
result = result + ((b[6] & MASK) << 8);
result = result + ((b[5] & MASK) << 16);
result = result + ((b[4] & MASK) << 24);
result = result + ((b[3] & MASK) << 32);
result = result + ((b[2] & MASK) << 40);
...
longtoLong(byte[] b)
Converts the first eight bytes of b to a 64-bit signed integer.
return toLong(b, 0);
longtoLong(byte[] b)
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;
...
longtoLong(byte[] b)
to Long
return toLong(b, 0);
longtoLong(byte[] b, int off, boolean bigEndian)
to Long
if (bigEndian) {
    return (((long) (b[0] & 0xff)) << 56) | (((long) (b[1] & 0xff)) << 48) | (((long) (b[2] & 0xff)) << 40)
            | (((long) (b[3] & 0xff)) << 32) | (((long) (b[4] & 0xff)) << 24)
            | (((long) (b[5] & 0xff)) << 16) | (((long) (b[6] & 0xff)) << 8) | ((long) (b[7] & 0xff));
} else {
    return (((long) (b[7] & 0xff)) << 56) | (((long) (b[6] & 0xff)) << 48) | (((long) (b[5] & 0xff)) << 40)
            | (((long) (b[4] & 0xff)) << 32) | (((long) (b[3] & 0xff)) << 24)
            | (((long) (b[2] & 0xff)) << 16) | (((long) (b[1] & 0xff)) << 8) | ((long) (b[0] & 0xff));
...