PHP Compiler
<!DOCTYPE html> <html> <body> <?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]; ?> </body> </html>
OUTPUT
Binary number of 500 (decimal) is 111110100
×

Save as Private