N/APosted on - 09/20/2011
I made an algorithm which generates binary numbers (with certain specifications), their minimum length is 15 bits.
Some of these numbers can't be stored in any integer data type (long data type has a maximum of 2147483647 using VS 2008's compiler).
I tried to store the numbers using string but failed.
Is there any way to store these numbers ? As I need them to be sorted too.
And if strings are possible, is there an easy solution to sort these numbers ?
How to store binary numbers of more than 15 bits
There are several solutions possible about your problem. First of all you know you cannot store that big numbers into one single int or long or double. But if you are working only with bits, (1 and 0) you can create an array of bits not a string, but an array, in C++ boolean type is stated to have value 1 or 0, so you can use an array of booleans to solve your problem, and for sorting the numbers you have to think about your algorithm. To create a boolean array use: bool  name = new bool [n];
Where name is the name of your array and n is the number of elements (bits in the number).