PHP Program to Converter a Binary to Decimal

Last Updated:

Converter a Number from Binary to Decimal

In the following example, we will convert a Binary number (1000001) to a Decimal number (65).

Tips: It is recommended to use our online Binary to Decimal converter for better understanding.

Example

PHP Compiler
<?php $num = 1000001; $arr = []; $i = -1; $total = 0; while($num != 0) { $i++; $arr[$i] = $num % 10; $num = $num / 10; $num = floor($num); } for($j=$i; $j>=0; $j--) $total += ($arr[$j] * pow(2, $j)); echo "Decimal number of 1000001 (binary) is $total"; ?>

Share this Page

Meet the Author