PHP Program to Converter a Decimal to Binary

Last Updated:

Converter a Number from Decimal to Binary

In the following example, we will convert a Decimal Number (500) to Binary Number (111110100).

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

Example

PHP Compiler
<?php $num = 500; $arr = []; $i = -1; while($num != 0) { $i++; $arr[$i] = $num % 2; $num = floor($num / 2); } echo "Binary number of 500 (decimal) is "; // reverse the array and display for($j=$i; $j>=0; $j--) echo $arr[$j]; ?>

Share this Page

Meet the Author