Android Int Base Convert fromOtherBaseToDecimal(int base, String number)

Here you can find the source of fromOtherBaseToDecimal(int base, String number)

Description

Converts a number from another base to the decimal counting system

Parameter

Parameter Description
base the base counting system of the input
number the input value to be converted

Return

the converted decimal value

Declaration

private static int fromOtherBaseToDecimal(int base, String number) 

Method Source Code

//package com.java2s;

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

    /**/*from   w ww.  ja v a 2  s  .co m*/
     * 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. fromBase36(String base36Number)