bitset STL
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
ll lcm(ll a,ll b)
{
ll r;
r=(a*b)/__gcd(a,b);
return r;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//bitset<31> bset; declaration
// bitset<31> bset(5);
//cout<<bset<<endl;
//string s="101";
// bitset<32>bset(s);
//bitset<32> bset(string("101")); another initialization
//cout<<bset.to_ulong()<<endl;
//oparation
bitset<10> bset;
bset.set();
cout<<bset<<endl;// all value will be one
bset=5;
cout<<bset<<endl;
cout<<bset.count()<<endl;//count number of one
bset.flip();//toggle all value;
cout<<bset<<endl;
cout<<bset[3]<<endl;//zero base index and start by rightmost bit
bset.reset();
cout<<bset<<endl;// all value will be zero
return 0;
}
0 Comments