calculate binary to decimal manually
问题 assuming I have a function to manually calculate decimal from binary number *up to four characters(binary) *assuming you can only input 0 and 1 character below code works perfectly function bin_to_dec($bin) { $bin = str_split($bin); $bin = array_reverse($bin); $i = 0; $dec = 0; foreach($bin as $values) { $ans = $values * pow(2, $i); $dec += $ans; $i++; } return $dec; } $bin = 1010 //4 $bin = 1 //1 $bin = 0 //0 assuming if you cannot use function strrev(), str_split(), array_reverse(), how