#include #include using namespace std; int main() { // Constructor bitset<8> b1; bitset<16> b2(1234); bitset<8> b3("1010"); string tenten("1010"); bitset<8> b4(tenten); cout << "b1 = " << b1 << endl; cout << "b2 = " << b2 << endl; cout << "b3 = " << b3 << endl; cout << "b4 = " << b4 << endl << endl; // set b1.set(); b2.set(15); cout << "b1 = " << b1 << endl; cout << "b2 = " << b2 << endl << endl; // reset, flip b1.reset(); b2.flip(); b3.flip(0); cout << "b1 = " << b1 << endl; cout << "b2 = " << b2 << endl; cout << "b3 = " << b3 << endl << endl; // all, any, none, count, size, test cout << "b2.all() = " << b2.all() << endl; cout << "b2.any() = " << b2.any() << endl; cout << "b2.none() = " << b2.none() << endl; cout << "b2.count() = " << b2.count() << endl; cout << "b2.size() = " << b2.size() << endl; cout << "b2.test(5) = " << b2.test(5) << endl << endl; // to_string, to ulong cout << "b3.to_string() = " << b3.to_string() << endl; cout << "b3.to_ulong() = " << b3.to_ulong() << endl << endl; auto somevariable = b3.to_ulong(); cout << sizeof(somevariable) << endl; // index operator b1[7] = 1; cout << b1[6] << ' ' << b1 << ' ' << b1.to_ulong() << endl << endl; cout << "b1 = " << b1 << endl; cout << "b3 = " << b3 << endl; cout << "b4 = " << b4 << endl << endl; // bitwise operators cout << "b1 | b3 = " << (b1 | b3) << endl; cout << "b3 & b4 = " << (b3 & b4) << endl; cout << "b3 ^ b4 = " << (b3 ^ b4) << endl; cout << "b3 << 2 = " << (b3 << 2) << endl; cout << "~b3 = " << (~b3) << endl; cout << "b1 |= b3 = " << (b1 |= b3) << endl; }