[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: valarray Up: The Standard Library Previous: map

bitset

This provides efficient operators on bits.
[fontsize=\small,frame=single,formatcom=\color{progcolor}]
#include <iostream>
#include <bitset>
using namespace std;

int main()
{
const unsigned int width = 32;
bitset<width> b1=23;
bitset<width> b2 = 1023;
bitset<width> b3;
 cout << "Type in a binary number (type a non-binary digit to end) ";
 cin >> b3;
 cout << "You typed " << b3 << endl; 
 cout << "b2 flipped=" << b2.flip() << endl;
 cout <<  "b1=" << b1 << endl;
return 0;
}



Tim Love
2001-07-05