Hi everyone. I want to know how to use a very large number of bitset.
A short version of my program:
1 2 3 4 5 6 7 8
constunsignedint T=4294967296; //Greatest number of unsigned int
int _tmain(int argc, _TCHAR* argv)
std::bitset<T> &x=*(new std::bitset<T>);
The program crash with a assestion that bitset index outside range.
The reason may be bitset only accept numbers in int range as parameter. When I reduce T by half, program runs fine.
How can I make bitset accept that large number, since my program need to generate repeatingly a random unsigned int and I need to check a number has been generated or not.
What I want to do is check every number from 0 to 2^32 if they have been generated, so I need 2^32 bit.
By the way, if I reduce T by half, the program (with 256 MB RAM) runs normally. In 32-bit program, we can allocate 2 GB RAM, so I think RAM is not a problem.
If unsigned int is 32 bits the largest value it can hold is 4294967295. If you try to assign the value 4294967296 to T the value will wrap-around and become 0. You can't store much in a zero-sized bitset!