Java Long to longToN62(long l)

Here you can find the source of longToN62(long l)

Description

long To N

License

Open Source License

Declaration

public static String longToN62(long l) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final char[] N62_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
            'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
            'U', 'V', 'W', 'X', 'Y', 'Z' };

    public static String longToN62(long l) {
        return longToNBuf(l, N62_CHARS).reverse().toString();
    }//  w w  w  .j a  v a  2  s .c om

    public static String longToN62(long l, int length) {
        StringBuilder sb = longToNBuf(l, N62_CHARS);
        for (int i = sb.length(); i < length; i++) {
            sb.append('0');
        }
        return sb.reverse().toString();
    }

    private static StringBuilder longToNBuf(long l, char[] chars) {
        int upgrade = chars.length;
        StringBuilder result = new StringBuilder();
        int last;
        while (l > 0) {
            last = (int) (l % upgrade);
            result.append(chars[last]);
            l /= upgrade;
        }
        return result;
    }
}

Related

  1. longToEightBytes(final long value)
  2. longToFourBytes(long value)
  3. longToFrontInt(long data)
  4. longToLex(long v)
  5. longToLittleEndianBytes(long value, byte[] destination, int offset, int length)
  6. longToName(long l)
  7. longToNBuf(long l, char[] chars)
  8. longToNetworkByteOrderArray(long addr)
  9. longToNetworkBytes(long value)