Binary To Decimal

This algorithm converts binary numbers to decimal numbers.



									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 = "10111101011011010111110";
$value = BinaryToDecimal($data);
								


Output

									6207166