3v4l.org

run code in 300+ PHP versions simultaneously
<?php // convert decimal to base 2 without using base_convert or printf $base = 2; $decnum = 23; $num = 23; $stack = array(); while( $num > 0) { $arr[] = $num % $base; // store remainder in array $num = floor($num/$base); // no integer division } var_dump($arr); $wrong = join('',$arr); var_dump($wrong); $cat = join('',array_reverse($arr)); var_dump($cat); printf("%b\n",$decnum); echo base_convert(23,10,2); // now using the stack while( $decnum > 0) { array_push($stack,($decnum % $base)); // store remainder on stack $decnum = floor($decnum/$base); // no integer division } while($stack) { echo array_pop($stack); } echo "\n";

preferences:
48.41 ms | 402 KiB | 5 Q