Reputation: 345
I have a ~100 digit string which represents a number in base 10 that I want to convert to either a string representing the number in base 2, or a bool array which represents the number's digits in binary. I can do it easily in Java using BigInteger, but I'm not sure if there is an equivalent in C++.
Function would be something like:
string toBinaryString(string numInDecimal);
Thanks for the help.
Upvotes: 2
Views: 1829
Reputation: 29877
Use the GNU Multiple Precision Arithmetic Library (GMP) available at http://gmplib.org. Then mpz set str is probably what you need to create a "BigInteger" from your string. And mpz get str to create a string again. Both functions take the base as parameter.
Upvotes: 2
Reputation: 8039
Unfortunately there is no standard C++ class/function to do that. Anyway, to give you at least some little help here are some more or less useful starting points to develop your own bigInt C++ class :
StackOverflow : How to implement big int in C++
SourceForge : C++ BigInt class
Upvotes: 1