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.
-
Uh... that's a hell a lot of digits in binary, and you're going to have some fun time handling it.
Either that, or you can use GMP to help you along...
-
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++
-
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.
0 comments:
Post a Comment