Reputation:
I have in C++ a vector of 32 bits integers (variable size, continous memory; like a C-array), representing a number in base 4294967296. I would like to print it in base 10.
These numbers can be extremely big and take over a few megabytes of memory.
What would be the best way to do this in terms of performance? Can I use GMP to do this?
Upvotes: 10
Views: 842
Reputation: 471249
Yes, you can use GMP for this. The function that you're looking for is mpn_get_str
:
http://gmplib.org/manual/Low_002dlevel-Functions.html#Low_002dlevel-Functions
Now the only issue is the size of mp_limb_t
. It is either a 32-bit integer or a 64-bit integer depending on the platform.
mpn_get_str
.Alternatively, it might be easier to use the mpz
integer class. Import your integer array into a large integer, then print it back out in base 10.
Upvotes: 7