ASCII To Octal

This algorithm converts ASCII code to octal numbers.



									function ASCIIToOctal($str)
{
	$oct = "";
	$strLen = strlen($str);

	for ($i = 0; $i < $strLen; $i++)
	{
		$cOct = DecimalToOctal(ord($str[$i]));

		if (strlen($cOct) < 3)
			$cOct = str_pad($cOct, 3, "0", STR_PAD_LEFT);

		$oct .= $cOct;
	}

	return $oct;
}

function DecimalToOctal($dec)
{
	if ($dec < 1) return "0";

	$octStr = "";

	while ($dec > 0)
	{
		$octStr = substr_replace($octStr, strval($dec % 8), 0, 0);
		$dec = floor($dec / 8);
	}

	return $octStr;
}
								


Example

									$data = "Programming Algorithms";
$value = ASCIIToOctal($data);
								


Output

									120162157147162141155155151156147040101154147157162151164150155163