tags:

views:

543

answers:

3

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.

A: 

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

Calyth
+1  A: 

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

Matt McCutchen : BigInt Class

AlexDrenea
+2  A: 

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.

f3lix