[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Big numbers in perl.

How can I convert big numbers from decimal to Hex?
0
sanek
Asked:
sanek
  • 5
  • 5
1 Solution
 
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 your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
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

Featured Post

Get expert help—faster!

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

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now