Java BigInteger Calculate base62Encode(BigInteger number)

Here you can find the source of base62Encode(BigInteger number)

Description

base Encode

License

Open Source License

Declaration

public static String base62Encode(BigInteger number) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *              OTj//from   ww  w  .  ja v  a2 s  .  co  m
 * Low-level client-side library for Open Transactions in Java
 * 
 * Copyright (C) 2013 by Piotr Kope? (kactech)
 * 
 * EMAIL: pepe.kopec@gmail.com
 * 
 * BITCOIN: 1ESADvST7ubsFce7aEi2B6c6E2tYd4mHQp
 * 
 * OFFICIAL PROJECT PAGE: https://github.com/kactech/OTj
 * 
 * -------------------------------------------------------
 * 
 * LICENSE:
 * This program is free software: you can redistribute it
 * and/or modify it under the terms of the GNU Affero
 * General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
 * section 7: If you modify this Program, or
 * any covered work, by linking or combining it with other
 * code, such other code is not for that reason alone subject
 * to any of the requirements of the GNU Affero GPL version 3.
 * (==> This means if you are only using the OTj, then you
 * don't have to open-source your code--only your changes to
 * OTj itself must be open source. Similar to
 * LGPLv3, except it applies to software-as-a-service, not
 * just to distributing binaries.)
 * Anyone using my library is given additional permission
 * to link their software with any BSD-licensed code.
 * 
 * -----------------------------------------------------
 * 
 * You should have received a copy of the GNU Affero General
 * Public License along with this program. If not, see:
 * http://www.gnu.org/licenses/
 * 
 * If you would like to use this software outside of the free
 * software license, please contact Piotr Kope?.
 * 
 * DISCLAIMER:
 * This program is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Affero General Public License for
 * more details.
 ******************************************************************************/

import java.math.BigInteger;

public class Main {
    private static final BigInteger B62_BASE = BigInteger.valueOf(62);
    public static final String B62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    public static String base62Encode(BigInteger number) {
        if (number.compareTo(BigInteger.ZERO) == -1) { // number < 0
            throw new IllegalArgumentException("number must not be negative");
        }
        StringBuilder result = new StringBuilder();
        while (number.compareTo(BigInteger.ZERO) == 1) { // number > 0
            BigInteger[] divmod = number.divideAndRemainder(B62_BASE);
            number = divmod[0];
            int digit = divmod[1].intValue();
            result.insert(0, B62_DIGITS.charAt(digit));
        }
        return (result.length() == 0) ? B62_DIGITS.substring(0, 1) : result.toString();
    }
}

Related

  1. areEqual(BigInteger[] a, BigInteger[] b)
  2. base128(BigInteger val)
  3. bitArrayToUnsignedBigInteger(int[] bits)
  4. bitcoinValueToFriendlyString(BigInteger value)
  5. byte_size(BigInteger bi)
  6. calculateGx(BigInteger p, BigInteger g, BigInteger x)