I've been trying to convert decimal integers into binary
and was using the following code
By repsonprint dec2bin(13) . "\n"; sub dec2bin { return (sprintf "%b",shift); }
but they don't work for numbers > 32 bits, is there an easy way to do this?sub to_bin { my $num = shift; my $ret = ''; while ($num){ $ret = (($num % 2) ? 1 : 0); $num >>= 1; } }
In reply to dec to bin conversion for large numbers by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |