- decbin: documentation ( source)
- floor: documentation ( source)
- str_pad: documentation ( source)
<?php
function Dec2Bin($number) {
while ($number >= 256) {
$bytes[] = (($number / 256) - (floor($number / 256))) * 256;
$number = floor($number / 256);
}
$bytes[] = $number;
for ($i=0;$i<count($bytes);$i++) {
$binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, "0", STR_PAD_LEFT)).$binstring;
}
return $binstring;
}
$float = PHP_FLOAT_MAX;
$bin = Dec2Bin($float);
$length = strlen($bin);
echo $bin . PHP_EOL;
echo $length .PHP_EOL;
echo $length / 8;