Android Int Base Convert fromBase36(String base36Number)

Here you can find the source of fromBase36(String base36Number)

Description

Converts a given Base36 value into its deciamal equivalent.

Parameter

Parameter Description
base36Number a parameter

Declaration

public static int fromBase36(String base36Number) 

Method Source Code

//package com.java2s;

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

    /**/* w  w  w  . j a  v  a2  s . com*/
     * Converts a given Base36 value into its deciamal equivalent.
     * @param base36Number
     * @return 
     */
    public static int fromBase36(String base36Number) {
        return fromOtherBaseToDecimal(36, base36Number);
    }

    /**
     * Converts a number from another base to the decimal counting system
     * @param base the base counting system of the input
     * @param number the input value to be converted
     * @return the converted decimal value
     */
    private static int fromOtherBaseToDecimal(int base, String number) {
        int iterator = number.length();
        int returnValue = 0;
        int multiplier = 1;

        while (iterator > 0) {
            returnValue = returnValue
                    + (baseDigits.indexOf(number.substring(iterator - 1,
                            iterator)) * multiplier);
            multiplier = multiplier * base;
            --iterator;
        }
        return returnValue;
    }
}

Related

  1. fromOtherBaseToDecimal(int base, String number)