Java Utililty Methods Int64 Convert

List of utility methods to do Int64 Convert

Description

The list of methods to do Int64 Convert are organized into topic(s).

Method

Objectint64(Object value)
int
if (value instanceof Number) {
    Number number = (Number) value;
    return number.longValue();
return value;
byte[]Int642Bytes(long sour)
Int Bytes
byte dest[] = { (byte) ((sour & 0xFF00000000000000L) >> 56), (byte) ((sour & 0x00FF000000000000L) >> 48),
        (byte) ((sour & 0x0000FF0000000000L) >> 40), (byte) ((sour & 0x000000FF00000000L) >> 32),
        (byte) ((sour & 0x00000000FF000000L) >> 24), (byte) ((sour & 0x0000000000FF0000L) >> 16),
        (byte) ((sour & 0x000000000000FF00L) >> 8), (byte) (sour & 0x00000000000000FF) };
return dest;
voidint64_to_buf(byte buf[], int pos, long value)
intbuf
buf[pos + 7] = (byte) (value >> 0);
buf[pos + 6] = (byte) (value >> 8);
buf[pos + 5] = (byte) (value >> 16);
buf[pos + 4] = (byte) (value >> 24);
buf[pos + 3] = (byte) (value >> 32);
buf[pos + 2] = (byte) (value >> 40);
buf[pos + 1] = (byte) (value >> 48);
buf[pos + 0] = (byte) (value >> 56);
...
longint64d(byte[] buf, int off)
intd
long b = 0;
for (int i = 0; i < 8; i++)
    b |= ((long) ub(buf[off + i])) << (i * 8);
return (b);
byte[]int64ToByteArray(long value, int size)
Converts an int64 into a byte array with a maximum size of 8.
if (size > 8) {
    return null;
byte[] tempResult = new byte[8];
clear(tempResult);
int offset = 7;
while (value != 0 && offset != -1) {
    tempResult[offset] = (byte) (value & 0xFF);
...
intint64toInt32(long key)
Hashes a long to an int
key = (~key) + (key << 18);
key = key ^ (key >>> 31);
key = key * 21;
key = key ^ (key >>> 11);
key = key + (key << 6);
key = key ^ (key >>> 22);
return (int) key;