function ToBin($n) {
$a = array();
do {
$r = floor($n) % 2; //calcolo il resto
$n = floor($n) / 2; //divido x 2
$a[] = $r;
} while ($n > 0.5);
$result=implode("",array_reverse($a));
$result = substr("00000000",0,8 - strlen($result)) . $result;
Echo $result;
}
$n = 8;
ToBin($n);