Hexadecimal To ASCII

This algorithm converts hexadecimal numbers to ASCII code.



									function HexadecimalToASCII($hex)
{
	$ascii = "";
	$hexLen = strlen($hex);

	for ($i = 0; $i < $hexLen; $i += 2)
	{
		$ascii .= chr(HexadecimalToDecimal(substr($hex, $i, 2)));
	}

	return $ascii;
}

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 = "50726F6772616D6D696E6720416C676F726974686D73";
$value = HexadecimalToASCII($data);
								


Output

									Programming Algorithms