Hexadecimal To Decimal

This algorithm converts hexadecimal numbers to decimal numbers.



									function HexadecimalToDecimal($hex)
{
	$hex = strtoupper($hex);

	$hexLength = strlen($hex);
	$dec = 0;

	for ($i = 0; $i < $hexLength; $i++)
	{
		$b = ord($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

									$data = "7660F";
$value = HexadecimalToDecimal($data);
								


Output

									484879