To convert a decimal integer to binary, repeatedly divide it by 2 — using integer division — until it becomes 0. The remainders at each step, which are 0s and 1s, represent the binary number, when strung together in the reverse order in which they were generated.
function dec2bin_i($decimal_i)
{
bcscale(0);
$binary_i = '';
do
{
$binary_i = bcmod($decimal_i,'2') . $binary_i;
$decimal_i = bcdiv($decimal_i,'2');
} while (bccomp($decimal_i,'0'));
return($binary_i);
}
?>
Test case
echo dec2bin_i('36893488147419103232'); //2^65
?>
Output: A 1 followed by 65 zeros:
100000000000000000000000000000000000000000000000000000000000000000