Here you can find the source of fromBase62(String base62Number)
Parameter | Description |
---|---|
base62Number | number in the base62 format we want to convert to the decimal format |
public static int fromBase62(String base62Number)
//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; } }