<? 

/* Currently 10 (16) relevant statements (this
 * includes echo's but not input check statements).
 * Date originally created: 27 & 28 August 2006
 * Date last edited: 14 September 2007
 * by Marno van der Molen - marno.homelinux.com
 * Test this at marno.homelinux.com/binary.php?nr=243
 * * * * * * * * * * * * * * * * * * * * * * * * * * */

// Get the userinput
if (is_numeric($_GET['nr'])) {
  
$nr $_GET['nr'];
} else {
  echo 
"fuck off, numbers only.";
  exit;
}

// Find biggest number that fits
for ($i 1$i <= $nr$i *= 2);

// Output some debugging info
echo "Input number is " $nr " and the biggest number that fits in there is " $i ".<br /><hr>";

// Calculate the binary digits
for (; $i >= 1$i /= 2) {
  if (
$nr >= $i) {
    
$result .= 1;
    
$nr -= $i;
  } else 
$result .= 0;
}

// Output
echo $result;
?>