Java BigInteger Calculate encodeToBase62(BigInteger num)

Here you can find the source of encodeToBase62(BigInteger num)

Description

encode To Base

License

Open Source License

Declaration

public static String encodeToBase62(BigInteger num) 

Method Source Code


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

import java.math.BigInteger;

public class Main {
    private static final String BASE62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final BigInteger SIXTY_TWO = new BigInteger("62");

    public static String encodeToBase62(byte[] bytes) {
        BigInteger value = new BigInteger(bytes);
        return encodeToBase62(value);
    }/*from   w w  w.j av  a2 s .c om*/

    public static String encodeToBase62(BigInteger num) {
        BigInteger value = BigInteger.ZERO.add(num);
        String result = "";
        while (!value.equals(BigInteger.ZERO)) {
            result = BASE62_DIGITS.charAt(value.mod(SIXTY_TWO).intValue()) + result;
            value = value.divide(SIXTY_TWO);
        }
        return result;
    }
}

Related

  1. encodeBigIntNoTypeCode(BigInteger value)
  2. encodeCompactBits(BigInteger value)
  3. encodeFloat(BigInteger j, int e)
  4. encodeInteger(BigInteger i, OutputStream os)
  5. encodeMPI(BigInteger value, boolean includeLength)
  6. encodeToString(final BigInteger input)
  7. encodeURL(BigInteger id)
  8. equal(BigInteger int1, BigInteger int2)
  9. equals(BigInteger[] a, BigInteger[] b)