Java Base Encode toBase36(int decimalNumber)

Here you can find the source of toBase36(int decimalNumber)

Description

to Base

License

Open Source License

Declaration

public static String toBase36(int decimalNumber) 

Method Source Code

//package com.java2s;
/***********************************************************************************
 * AlgoTrader Enterprise Trading Framework
 *
 * Copyright (C) 2015 AlgoTrader GmbH - All rights reserved
 *
 * All information contained herein is, and remains the property of AlgoTrader GmbH.
 * The intellectual and technical concepts contained herein are proprietary to
 * AlgoTrader GmbH. Modification, translation, reverse engineering, decompilation,
 * disassembly or reproduction of this material is strictly forbidden unless prior
 * written permission is obtained from AlgoTrader GmbH
 *
 * Fur detailed terms and conditions consult the file LICENSE.txt or contact
 *
 * AlgoTrader GmbH/*from   www  . ja  va 2 s.  c  o m*/
 * Aeschstrasse 6
 * 8834 Schindellegi
 ***********************************************************************************/

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

    public static String toBase36(int decimalNumber) {
        return fromDecimalToOtherBase(36, decimalNumber);
    }

    private static String fromDecimalToOtherBase(int base, int decimalNumber) {
        String tempVal = decimalNumber == 0 ? "0" : "";
        int mod = 0;

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

        return tempVal;
    }
}

Related

  1. ToBase16(StringBuilder str, byte[] data)
  2. toBase2(byte b)
  3. toBase26(int number)
  4. toBase2SuffixedString(long n)
  5. toBase32Char(int i)
  6. toBase36(long l)
  7. toBase36(long num)
  8. toBase62(int decimalNumber)
  9. toBase8(int decimalNumber)