Java Number Invert invertNumeral(int base, String number)

Here you can find the source of invertNumeral(int base, String number)

Description

invert Numeral

License

Apache License

Parameter

Parameter Description
base (Numeral System)
number a parameter

Declaration

public static long invertNumeral(int base, String number) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w ww . j  av a 2  s . c  o m
     * @param base (Numeral System)
     * @param number
     * @return
     */
    public static long invertNumeral(int base, String number) {

        long decimal = 0;
        char[] c = number.toCharArray();

        for (int i = 0; i < c.length; i++) {

            if ((c[i] >= '\u0030') && (c[i] <= '\u0039')) { // 0-9
                decimal = decimal * base + c[i] - '\u0030';
            } else if (c[i] >= '\u0041' && c[i] <= '\u005A') { // A-Z
                decimal = decimal * base + c[i] - '\u0041' + 10;
            } else if (c[i] >= '\u0061' && c[i] <= '\u007A') { // a-z
                decimal = decimal * base + c[i] - '\u0041' + 4;
            }

        }

        return decimal;

    }
}

Related

  1. invert(float value)
  2. invert(int numToInvert)
  3. invert3x3(final double m00, final double m01, final double m02, final double m10, final double m11, final double m12, final double m20, final double m21, final double m22)
  4. invertFloat(float n)
  5. invertFloat(float number)