Hexadecimal To Decimal

This algorithm converts hexadecimal numbers to decimal numbers.



									/*****Please include following header files*****/
// math.h
/***********************************************/

int HexadecimalToDecimal(char* hex) {
	int hexLength = strlen(hex);
	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

									char* data = "7660F";
int value = HexadecimalToDecimal(data);
								


Output

									484879