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 thi
The following code should help you:
bitset<20> b; bool overflow = false; while( ! overflow ){ cout << b << endl; // prints bits in reversed order int ipos = b.size(); overflow = true; while( overflow && --ipos >= 0 ){ overflow = b[ipos]; b[ipos] = ! b[ipos]; } }
tested by @Jarod42, thanks.