I have a string contains 64 binary symbols.
I need to convert it into the decimal number. How can I do it in perl?
sub bin2dec {
return unpack("N", pack("B64", substr("0" x 64 . shift, -64)));
}
doesn’t work. it converts just first 32 bit.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From the docs,
The 64 bit equivalent would be “
Q>“.So you could use the following:
That said, the above is needlessly complicated. Whoever coded that was was probably not aware of
oct‘s ability to parse binary numbers because the above can be reduced toBut what do you do if you don’t have a 64-bit build of Perl? You need to use some kind of object that overloads math operations. You could use Math::BigInt, but I suspect that won’t be nearly as fast as Math::Int64.
For example,