Java Base Convert fromBase62(String base62Number)

Here you can find the source of fromBase62(String base62Number)

Description

from Base

License

Open Source License

Parameter

Parameter Description
base62Number number in the base62 format we want to convert to the decimal format

Return

decimal representation of the base62 number

Declaration

public static int fromBase62(String base62Number) 

Method Source Code

//package com.java2s;
/*/*from   ww w  .  ja va  2s  .  com*/
 Copyright (C) 2009 maik.jablonski@gmail.com
    
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 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 General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    private static final String baseDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    /**
     * 
     * @param base62Number number in the base62 format we want to 
     * convert to the decimal format
     * @return decimal representation of the base62 number
     */
    public static int fromBase62(String base62Number) {
        return fromOtherBaseToDecimal(62, base62Number);
    }

    private static int fromOtherBaseToDecimal(int base, String number) {
        int result = 0;
        for (int pos = number.length(), multiplier = 1; pos > 0; pos--) {
            result += baseDigits.indexOf(number.substring(pos - 1, pos)) * multiplier;
            multiplier *= base;
        }
        return result;
    }
}

Related

  1. fromBase16toIntArray(String bytes)
  2. fromBase26(String number)
  3. fromBase36(String base36)
  4. fromBase36(String base36Number)
  5. fromBase58(String input)