|Do you know where your variables are?|
Answer: How do I convert between decimal and binary?by vroom (Pope)
|on Feb 01, 2000 at 23:48 UTC||Need Help??|
We need to use pack and unpack because printf or sprintf don't have any way of dealing with binary numbers. Here are two functions that should do the job though:
To turn a perl integer into a binary string we must first pack it into network byte order which the "N" format stands for. Then we unpack it into the "B32" format. We then strip off all leading 0's with a simple substitution.
For the bin2dec function we simply reverse the process. First we pad the number with the correct number of 0's and then reversing what we did in the previous function