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

Stringlong2MacAddress(long l)
long Mac Address
StringBuilder sb = new StringBuilder(17);
sb.append(toHex((byte) ((l >> 44) & 0xf)));
sb.append(toHex((byte) ((l >> 40) & 0xf)));
sb.append(":");
sb.append(toHex((byte) ((l >> 36) & 0xf)));
sb.append(toHex((byte) ((l >> 32) & 0xf)));
sb.append(":");
sb.append(toHex((byte) ((l >> 38) & 0xf)));
...
byte[]long2minLeb(final long x)
longmin Leb
if (x <= 0xFFFFFFFFFFFFFFL) {
    if (x <= 0xFFFFFFFFFFFFL) {
        if (x <= 0xFFFFFFFFFFL) {
            if (x <= 0xFFFFFFFFL) {
                if (x <= 0xFFFFFFL) {
                    if (x <= 0xFFFFL) {
                        if (x <= 0xFFL) {
                            if (x < 0)
...
StringlongTo36Str(String str)
long To Str
StringBuilder sb = new StringBuilder(10);
int size = str.length() / 2 * 2;
int mod = str.length() % 2;
if (size > 0) {
    for (int i = 0; i < size; i = i + 2) {
        int a = Integer.valueOf(str.substring(i, i + 2));
        sb.append(Integer.toString(a, 36));
if (mod > 0) {
    sb.append(str.substring(str.length() - 1));
return sb.toString();
intlongTo4ByteArray(byte[] bytes, int offset, long value)
long To Byte Array
bytes[offset + 3] = (byte) value;
bytes[offset + 2] = (byte) (value >> 8);
bytes[offset + 1] = (byte) (value >> 16);
bytes[offset + 0] = (byte) (value >> 24);
return 4;
byte[]longTo4LengthBytes(long num)
long To Length Bytes
int i = (int) (num);
return intToBytes(i);
intLongToAscii(long number, byte[] buf, int offset, int length)
Long To Ascii
return LongToString(number, buf, offset, length, false);
intlongToBaseCode(char[] target, int targetOffset, long value, int base, int lengthLimit, boolean fillZeros, boolean upperCase)
Converts long value to code of given base and length limit.
char[] codes = upperCase ? UPPER_HEX_CODES : LOWER_HEX_CODES;
for (int i = lengthLimit - 1; i >= 0; i--) {
    target[targetOffset + i] = codes[(int) (value % base)];
    if (!fillZeros && value == 0) {
        return i;
    value = value / base;
return 0;
TlongToBasicType(long l, Class clazz)
long To Basic Type
if (clazz.equals(Boolean.class))
    return (T) Boolean.valueOf(longToBoolean(l));
if (clazz.equals(Byte.class))
    return (T) longToByte(l);
if (clazz.equals(Character.class))
    return (T) longToCharacter(l);
if (clazz.equals(Short.class))
    return (T) longToShort(l);
...
byte[]longToBcd(long num, int size)
long To Bcd
int digits = 0;
long temp = num;
while (temp != 0) {
    digits++;
    temp /= 10;
int byteLen = digits % 2 == 0 ? digits / 2 : (digits + 1) / 2;
boolean isOdd = digits % 2 != 0;
...
byte[]longToBcd(long src, int len, int flag)
long To Bcd
byte[] re = new byte[len];
long tmp, high, low;
if (src < 0)
    throw new RuntimeException(String.format("number: [%d] convert bcd error", src));
for (int i = len - 1; i >= 0; i--) {
    if (src == 0)
        break;
    if (flag == 1) {
...