Here you can find the source of invertNumeral(int base, String number)
Parameter | Description |
---|---|
base | (Numeral System) |
number | a parameter |
public static long invertNumeral(int base, String number)
//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; } }