Hexadecimal To Decimal

This algorithm converts hexadecimal numbers to decimal numbers.



									/*****Please include following header files*****/
// string
/***********************************************/

/*****Please use following namespaces*****/
// std
/*****************************************/

static int HexadecimalToDecimal(string hex) {
	int hexLength = hex.length();
	double dec = 0;

	for (int i = 0; i < hexLength; ++i)
	{
		char b = hex[i];

		if (b >= 48 && b <= 57)
			b -= 48;
		else if (b >= 65 && b <= 70)
			b -= 55;

		dec += b * pow(16, ((hexLength - i) - 1));
	}

	return (int)dec;
}
								


Example

									string data = "7660F";
int value = HexadecimalToDecimal(data);
								


Output

									484879