Android Decimal Format fromDecimalToOtherBase(long base, long decimalNumber)

Here you can find the source of fromDecimalToOtherBase(long base, long decimalNumber)

Description

Converts a decimal number to another counting system.

Parameter

Parameter Description
base the counting system to convert the the number to.
decimalNumber the input number to be converted

Return

the converted number

Declaration

private static String fromDecimalToOtherBase(long base,
        long decimalNumber) 

Method Source Code

//package com.java2s;

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

    /**/*from w ww.  ja v a 2s.com*/
     * Converts a decimal number to another counting system.
     * @param base the counting system to convert the the number to.
     * @param decimalNumber the input number to be converted
     * @return the converted number
     */
    private static String fromDecimalToOtherBase(long base,
            long decimalNumber) {
        String tempVal = decimalNumber == 0 ? "0" : "";
        long mod;

        while (decimalNumber != 0) {
            mod = decimalNumber % base;
            tempVal = baseDigits.substring((int) mod, (int) (mod + 1))
                    + tempVal;
            decimalNumber = decimalNumber / base;
        }

        return tempVal;
    }
}