霍纳算法,将十六进制字符串转换为十进制数的高效算法

hexToDecimal(hex.toUpperCase())
	
	public static int hexToDecimal(String hex) {
		int deciamlValue = 0;
		for(int i = 0; i < hex.length(); i++){
			char hexChar = hex.charAt(i);
			deciamlValue = deciamlValue * 16 + hexCharDecimal(hexChar);
		}
		return deciamlValue;
		
	}

	private static int hexCharDecimal(char hexChar) {
		if(hexChar >= 'A' && hexChar <= 'F')
			return 10 + hexChar - 'A';
		else
			return hexChar - '0';
	}

你可能感兴趣的:(Prime,Methods)