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

long[]toLong(double[] v)
to Long
final long[] ans = new long[v.length];
for (int k = 0; k < v.length; k++)
    ans[k] = (long) v[k];
return (ans);
longtoLong(final byte[] array, final int offset, final int length)
to Long
long result = 0;
for (int i = (offset + length - 1); i >= offset; i--) {
    result <<= 8;
    result |= (array[i] & 0xFF);
return result;
longtoLong(final byte[] b)
Converts the bytes in an array into the corresponding long value.
return toLong(b, 0);
longtoLong(final byte[] b, final int offset)
to Long
return ((b[offset + 7] & 0xFFL)) + ((b[offset + 6] & 0xFFL) << 8) + ((b[offset + 5] & 0xFFL) << 16)
        + ((b[offset + 4] & 0xFFL) << 24) + ((b[offset + 3] & 0xFFL) << 32)
        + ((b[offset + 2] & 0xFFL) << 40) + ((b[offset + 1] & 0xFFL) << 48) + (((long) b[offset]) << 56);
longtoLong(final byte[] bytes, final int offset)
to Long
final long high = (long) toInt(bytes, offset) << 32;
final long low = (long) toInt(bytes, offset + 4) << 32 >>> 32;
return high | low;
longtoLong(final byte[] data)
Converts the big-endian representation of a 64-bit integer to the equivalent long value.
return ((long) data[0] << 56) | (((long) data[1] & 0xff) << 48) | (((long) data[2] & 0xff) << 40)
        | (((long) data[3] & 0xff) << 32) | (((long) data[4] & 0xff) << 24)
        | (((long) data[5] & 0xff) << 16) | (((long) data[6] & 0xff) << 8) | ((long) data[7] & 0xff);
longtoLong(final byte[] data)
Converts the 8-byte value to a Big Endian long
if (data.length != 8) {
    throw new IllegalArgumentException("data must be of length 8");
return toLong(data, 0);
longtoLong(final byte[] inputBytes, int offset)
Form a Long value reading 8 bytes
if (0 == inputBytes.length)
    return 0;
long longVal = (((long) (inputBytes[offset])) << 56) + ((inputBytes[++offset] & 0xffL) << 48)
        + ((inputBytes[++offset] & 0xffL) << 40) + ((inputBytes[++offset] & 0xffL) << 32)
        + ((inputBytes[++offset] & 0xffL) << 24) + ((inputBytes[++offset] & 0xff) << 16)
        + ((inputBytes[++offset] & 0xff) << 8) + (inputBytes[++offset] & 0xff);
return longVal;
LongtoLong(final Object o, final String pattern)
to Long
if (o == null) {
    return null;
} else if (o instanceof Long) {
    return (Long) o;
} else if (o instanceof Number) {
    return Long.valueOf(((Number) o).longValue());
} else if (o instanceof String) {
    return toLong((String) o);
...
longtoLong(final Object obj)
to Long
try {
    if (obj instanceof String) {
        return Long.valueOf((String) obj).longValue();
    } else if (obj instanceof Number) {
        return ((Number) obj).longValue();
    } else {
        throw new IllegalArgumentException("Could not convert value to integer: " + obj);
} catch (Exception e) {
    throw new IllegalArgumentException("Could not convert value to number: " + obj, e);