Java Utililty Methods Long to

List of utility methods to do Long to

Description

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

Method

voidlongToBigEndian(long value, byte[] in, int offset)
long To Big Endian
if (in == null) {
    throw new NullPointerException("in == null");
if ((in.length - offset) < 8) {
    throw new IllegalArgumentException("not enough space in array");
in[offset] = (byte) ((value >> 56) & 0xff);
in[offset + 1] = (byte) ((value >> 48) & 0xff);
...
StringlongToBinary(long num)
A quick method to convert num to a binary number.
return Long.toString(num, 2); 
Stringlongtobinarystring(long wert, int bits)
longtobinarystring
StringBuilder text = new StringBuilder();
for (int i = bits; i > 0; i--) {
    text.append(Math.abs(wert % 2));
    wert /= 2;
text.reverse();
return text.toString();
StringlongToBinaryStringUnsigned(long value)
long To Binary String Unsigned
return Long.toBinaryString(Math.abs(value));
intlongToBucket(long key, int buckets)
long To Bucket
key = (~key) + (key << 18); 
key ^= (key >>> 31);
key *= 21; 
key ^= (key >>> 11);
key += (key << 6);
key ^= (key >>> 22);
int result = ((int) key) % buckets;
return result < 0 ? result + buckets : result;
...
voidLongToBuf4(long val, byte[] buf, int offset)
Long To Buf
assert buf.length >= offset + 4;
buf[offset] = (byte) (val & 0xFF);
buf[offset + 1] = (byte) ((val >> 8) & 0xFF);
buf[offset + 2] = (byte) ((val >> 16) & 0xFF);
buf[offset + 3] = (byte) ((val >> 24) & 0xFF);
voidlongToBuffer(long l, byte[] ioBuffer)
long To Buffer
ioBuffer[0] = (byte) (l >>> 56);
ioBuffer[1] = (byte) (l >>> 48);
ioBuffer[2] = (byte) (l >>> 40);
ioBuffer[3] = (byte) (l >>> 32);
ioBuffer[4] = (byte) (l >>> 24);
ioBuffer[5] = (byte) (l >>> 16);
ioBuffer[6] = (byte) (l >>> 8);
ioBuffer[7] = (byte) l;
...
char[]longToCharArray(long seat, int length)
long To Char Array
String seatString = Long.toBinaryString(seat);
int longLength = seatString.length();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length - longLength; i++) {
    sb.append('0');
sb.append(seatString);
return sb.toString().toCharArray();
...
charlongToCharBounds(long value)
casts a long to an char, but if the long is outside the char-range, it will mapped to the end of the range
if (value > Character.MAX_VALUE)
    return Character.MAX_VALUE;
else if (value < Character.MIN_VALUE)
    return Character.MIN_VALUE;
else
    return (char) value;
longlongToCompare(Long value)
long To Compare
return value == null ? -1 : value;