Octal To ASCII

This algorithm converts octal numbers to ASCII code.



									function OctalToASCII($oct)
{
	$ascii = "";
	$octLen = strlen($oct);

	for ($i = 0; $i < $octLen; $i += 3)
	{
		$ascii .= chr(OctalToDecimal(substr($oct, $i, 3)));
	}

	return $ascii;
}

function OctalToDecimal($octal)
{
	$octLength = strlen($octal);
	$dec = 0;

	for ($i = 0; $i < $octLength; $i++)
	{
		$dec += (ord($octal[$i]) - 48) * pow(8, (($octLength - $i) - 1));
	}

	return (int)$dec;
}
								


Example

									$data = "120162157147162141155155151156147040101154147157162151164150155163";
$value = OctalToASCII($data);
								


Output

									Programming Algorithms