in reply to How turn a huge decimal number to binary
If you are just playing with powers 1024, it might be good enough to know that the binary representation for 1024 is a "1" followed by 10 zeros. That is:
For each power of 1024, just add ten more zeros:$binary_string = "1" . "0" x 10; print "$binary_string\n"
But I assume you are really trying to do something more complicated than that. For example, if you are trying to read a string of decimal digits of arbitrary length, and convert that to binary, I'm not sure anyone has posted a good solution for that yet. (I don't have a good solution for that, but I'm sure one can be found...)$power = 4; $binary_string = "1" . "0" x (10 * $power); # parens required print "$binary_string\n"
|
|---|