Java Base Encode toBase10(final String base62)

Here you can find the source of toBase10(final String base62)

Description

to Base

License

Open Source License

Parameter

Parameter Description
base62 number

Return

converted number into Base10

Declaration

public static Long toBase10(final String base62) 

Method Source Code

//package com.java2s;
/**//from  w w  w .  j  a  v a2 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 base62
     *            number
     * @return converted number into Base10
     */
    public static Long toBase10(final String base62) {
        return toBase10(new StringBuilder(base62).reverse().toString().toCharArray());
    }

    private static Long toBase10(final char[] chars) {
        long base10 = 0L;
        for (int i = chars.length - 1; i >= 0; i--) {
            base10 += toBase10(BASE62_ALPHABET.indexOf(chars[i]), i);
        }
        return base10;
    }

    private static int toBase10(final int n, final int pow) {
        return n * (int) Math.pow(BASE62_BASE, pow);
    }
}

Related

  1. toBase(long startMillis, long currentMillis, long baseMillis)
  2. toBase10(int[] arr)
  3. toBase10(int[] arr)
  4. toBase10SuffixedString(long n)
  5. toBase16(byte[] data)