I want to add 1 value to the bitset until it over flows, I am wondering how to do this, like:
bitset<20> foo; (foo=00000 00000 00000 00000) how can we implement this function, continuously add one
00000 00000 00000 00000 00000 > 00000 00000 00000 00000 00001 > 00000 00000 00000 00000 >00010 > 00000 00000 00000 00000 000011 until it overflows?
I am thinking about two ways;
foo.to_ulong();
how to convert unsigned long back to bitset again? C++ documentation indicates it is possible, but in the library, I can only see bitset (unsigned long val), which is creating a new bitset
2. somehow bit operations, both got stuck, help needed
You may use the following: http://ideone.com/C8O8Qe
And then to iterate on all values :
The following code should help you:
tested by @Jarod42, thanks.