I want to know how is this program working:
#include <bitset>
#include <iostream>
const int option_1 = 0;
const int option_2 = 1;
const int option_3 = 2;
const int option_4 = 3;
const int option_5 = 4;
const int option_6 = 5;
const int option_7 = 6;
const int option_8 = 7;
int main()
{
std::bitset<8> bits(0x2);
bits.set(option_5);
bits.flip(option_6);
bits.reset(option_6);
std::cout << "Bit 4 has value: " << bits.test(option_5) << '\n';
std::cout << "Bit 5 has value: " << bits.test(option_6) << '\n';
std::cout << "All the bits: " << bits << '\n';
return 0;
}
I have seen this example on a website, But cannot understand the working of some part of this program.
here, first option5 is set to 4, then in main program "bit.set(option5);" is used to set it to 1(is what i think). then what is use of that 4 assigned to integer option5 above??