c++ - working of std::bitset in cpp -


i want know how 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 bits: " << bits << '\n';         return 0;  }

i have seen example on website, cannot understand working of part of program.
here, first option5 set 4, in main program "bit.set(option5);" used set 1(is think). use of 4 assigned integer option5 above??

so @ high level array of bits. using non type templating array of bits created on stack.

the option5 variable used set fourth bit (from when printed) 1. when print out values there 1 in location pointed option5 location 4 back.

the constructor of bitset used initialize bitset 0b00000010. set() function sets bit @ location specified 1, reset() function sets bit @ location specified 0.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -