from Base 36 number - Java java.lang

Java examples for java.lang:Number

Description

from Base 36 number

Demo Code


//package com.java2s;

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

    public static int fromBase36(String base36Number) {
        return fromOtherBaseToDecimal(36, base36Number);
    }/*from   w  w w . jav  a2  s.c o m*/

    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 Tutorials