Big numbers in perl.

How can I convert big numbers from decimal to Hex?
LVL 2
sanekAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Do you mean Math::BigInt numbers?
0
sanekAuthor Commented:
I've pretty long string of \d chars that cannot be converted with sprintf("%X", $str).
Let's say that decimal value can reach upto 2^64 (8 bytes)
0
ozoCommented:
perl -MMath::BigInt=:constant -e '$x=shift; printf"%08X%08X\n",$x/2**32,$x%2**32' 9876543210987654321
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

sanekAuthor Commented:
Hmm... That's doesn't work :(
It ouputs result 891087B87FFFFFFF
And it's always 7fffffff in $x%2**32
0
ozoCommented:
Sounds like you left out the -MMath::BigInt=:constant
0
sanekAuthor Commented:
I've just copy&past-ed the whole string into command line. I understand this is the way that should work.
0
ozoCommented:
Hmm, what do you get from
perl -MMath::BigInt -e '$x= new Math::BigInt shift; printf"%s %s\n",$x/2**32,$x%2**32' 9876543210987654321
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sanekAuthor Commented:
I get
+2299561912+3820424369
In a case I substitute "%s%s" with "%X%X" - I receive:
891087B8E3B70CB1

What, I suppose, is correct.
Thanks, ozo.
0
ozoCommented:
You probably want to substitiute %08X%08X, in case you get a number like 9876543207167229953
I guess you must have a version of Math::BigInt that doesn't support :constant, sorry.
0
sanekAuthor Commented:
Oh yeah, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.