Test value in a bitset : bitset « bitset « C++ Tutorial






#include <bitset>
#include <iostream>
using namespace std;

int main(int argc, char** argv){
  bitset<10> myBitset;

  myBitset.set(3);
  myBitset.set(6);
  myBitset[8] = true;
  myBitset[9] = myBitset[3];

  if (myBitset.test(3)) {
    cout << "Bit 3 is set!\n";
  }
  cout << myBitset << endl;

  return (0);
}








18.1.bitset
18.1.1.Initialize a bitset with hex number
18.1.2.A bitset to hold 8-bits
18.1.3.Read a binary number into a bitset
18.1.4.Test value in a bitset
18.1.5.Create a copy of a bitset
18.1.6.Reset bit in a bitset
18.1.7.instantiate a bitset object for 8 bits, given an unsigned long init value
18.1.8.Instantiate a bitset object for holding 5 bits, initialize it to a bit sequence supplied by a string
18.1.9.Instantiate a bitset object for holding 4 bits, all initialized to '0000'
18.1.10.write a decimal integer as a binary number
18.1.11.Use bitset with enum together