Binary To ASCII

This algorithm converts binary numbers to ASCII code.



									function BinaryToASCII($bin)
{
	$ascii = "";
	$binLen = strlen($bin);

	for ($i = 0; $i < $binLen; $i += 8)
	{
		$ascii .= chr(BinaryToDecimal(substr($bin, $i, 8)));
	}

	return $ascii;
}

function BinaryToDecimal($bin)
{
	$binLength = strlen($bin);
	$dec = 0;

	for ($i = 0; $i < $binLength; $i++)
	{
		$dec += (ord($bin[$i]) - 48) * pow(2, (($binLength - $i) - 1));
	}

	return (int)$dec;
}
								


Example

									$data = "01010000011100100110111101100111011100100110000101101101011011010110100101101110011001110010000001000001011011000110011101101111011100100110100101110100011010000110110101110011";
$value = BinaryToASCII($data);
								


Output

									Programming Algorithms