Java Utililty Methods Long Number Convert To

List of utility methods to do Long Number Convert To

Description

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

Method

byte[]fromLong(long longValue)
Interpret a long as its binary form
byte[] bytes = new byte[8];
bytes[0] = (byte) (longValue >> 56);
bytes[1] = (byte) ((longValue << 8) >> 56);
bytes[2] = (byte) ((longValue << 16) >> 56);
bytes[3] = (byte) ((longValue << 24) >> 56);
bytes[4] = (byte) ((longValue << 32) >> 56);
bytes[5] = (byte) ((longValue << 40) >> 56);
bytes[6] = (byte) ((longValue << 48) >> 56);
...
voidfromLong(long v, int offset, byte[] dest)
from Long
assert (dest.length >= (8 + offset));
dest[0 + offset] = (byte) ((v >> 56) & 0xff);
dest[1 + offset] = (byte) ((v >> 48) & 0xff);
dest[2 + offset] = (byte) ((v >> 40) & 0xff);
dest[3 + offset] = (byte) ((v >> 32) & 0xff);
dest[4 + offset] = (byte) ((v >> 24) & 0xff);
dest[5 + offset] = (byte) ((v >> 16) & 0xff);
dest[6 + offset] = (byte) ((v >> 8) & 0xff);
...
StringfromLong(Long value)
from Long
return Long.toString(value);
byte[]fromLong(long value)
Converts a long value to a byte array.
byte[] result = { (byte) (0xFFL & (value >>> 56)), (byte) (0xFFL & (value >>> 48)),
        (byte) (0xFFL & (value >>> 40)), (byte) (0xFFL & (value >>> 32)), (byte) (0xFFL & (value >>> 24)),
        (byte) (0xFFL & (value >>> 16)), (byte) (0xFFL & (value >>> 8)), (byte) (0xFFL & value) };
return result;
byte[]fromLong(long value, int numBytes)
from Long
long mask = 0xFF;
byte[] res = new byte[numBytes];
for (int i = 0; i < numBytes; i++) {
    res[i] = (byte) (value & mask);
    value = value >> 8;
return res;
byte[]fromLong(long x)
from Long
byte[] result = new byte[8];
result[0] = (byte) ((x >> 56) & 0xFF);
result[1] = (byte) ((x >> 48) & 0xFF);
result[2] = (byte) ((x >> 40) & 0xFF);
result[3] = (byte) ((x >> 32) & 0xFF);
result[4] = (byte) ((x >> 24) & 0xFF);
result[5] = (byte) ((x >> 16) & 0xFF);
result[6] = (byte) ((x >> 8) & 0xFF);
...
LongfromLongString(String longString)
Parses the specified string as a Long instance.
if (longString == null || longString.trim().isEmpty()) {
    return ZERO_LONG;
try {
    return Long.parseLong(longString);
} catch (Exception e) {
    return 0L;