// // This function converts binair to decimal // function binair2decimal($number){ $length = strlen($number); // Fetch the length of the binair input $current = 1; $sum = 0; // // Loop through each character of the binair input, increase $current by the power of 2 // for($i = 1; $i < $length; $i++){ $current = $current * 2; } // // Loop through each character of the binair input again // for($i = 0; $i < $length; $i++){ // // Check if the current character is a 1 // if($number{$i} === "1"){ // // Increase the current sum // $sum = $sum + (1 * $current); } // // Divide current by 2 for the next character // $current = $current / 2; } // // Return the sum // return $sum; }