Java Base Convert fromBase10(final long base10)

Here you can find the source of fromBase10(final long base10)

Description

from Base

License

Open Source License

Parameter

Parameter Description
base10 number

Return

converted number into Base62 ASCII string

Declaration

public static String fromBase10(final long base10) 

Method Source Code

//package com.java2s;
/**//www .  j a v  a  2 s.  c o  m
 * Copyright (c) 2015 Bosch Software Innovations GmbH and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    private static final String BASE62_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final int BASE62_BASE = BASE62_ALPHABET.length();

    /**
     * @param base10
     *            number
     * @return converted number into Base62 ASCII string
     */
    public static String fromBase10(final long base10) {
        if (base10 == 0) {
            return "0";
        }

        long temp = base10;
        final StringBuilder sb = new StringBuilder();

        while (temp > 0) {
            temp = fromBase10(temp, sb);
        }
        return sb.reverse().toString();
    }

    private static Long fromBase10(final long base10, final StringBuilder sb) {
        final int rem = (int) (base10 % BASE62_BASE);
        sb.append(BASE62_ALPHABET.charAt(rem));
        return base10 / BASE62_BASE;
    }
}

Related

  1. fromBase(String num, String baseChars)
  2. fromBase16(String data)
  3. fromBase16toByteArray(String bytes)
  4. fromBase16toIntArray(String bytes)
  5. fromBase26(String number)