//第二十三模板 18.3.5 位集合
//Bitsets给程序员提供一种位集合的数据结构,这种位集合的通二进制的因此Bitsets提供了许多位操作符,比如!= == &= ^= |= ~ <<= >>= []
//1 Bitsets的创建
/*#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8>bs( (long)131 );
for(int i=(int)bs.size()-1; i>=0; i--)
{
cout<<bs[i]<<" ";
}
cout<<endl;
cout<<bs<<endl;
system("pause");
return 0;
}*/
//2 Bitsets类重载的过算符
//bitset类重载的所有运算符如下
//!= == &= ^= |= ~ <<= >>= []
/*
!= 如果两个bitset不相等返回真
== 如果两个bitset相等返回值
&= 完成两个bitset间的与运算
^= 完成两个bitset间的异或运算
|= 完成两个bitset间或运算
~ 反置bitset
<<= 把bitset向左移动
>>= 把bitset向右移动
[x] 返顺第x个位的引用
*/
/*
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8>bs( (long)131 );
cout<<bs<<endl;
cout<<~bs<<endl;
system("pause");
return 0;
}*/
//3 Bitsets类的其它方法
//any() 如查有任何一个位被设置,就返回true
//cout() 返回被设置的位的个数
//flip() 返回bits中的位
//none() 如果没有位被设置,则返回true
//reset() 清空所有位
//set() 设置位
//size() 返回可以容纳的位的个数
//test() 返回指定位的状态
//to_string() 返回bitset的字符串表示
//to_ulong() 返回ibtset的整数表示
/*
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<8>bs( (long)131 );
//cout<<bs<<endl;
//cout<<~bs<<endl;
//(1) flip()方法 与反置运逄符合~作用相同
cout<<"flip:"<<bs.flip()<<endl;
//(2) none方法
cout<<"none:"<<bs.none()<<endl;
//(3)any()方法 与none()方法相反
cout<<"any:"<<bs.any()<<endl;
//(4) reset();方法
//bs.reset();
//cout<<"none:"<<bs.none()<<endl;
//(5)size方法
cout<<"size:"<<bs.size()<<endl;
//(6)test()方法
cout<<"test:"<<bs.test(3)<<endl;
//(7)set()方法
cout<<bs<<endl;
bs.set(0,1);
cout<<bs<<endl;
//(8)to_string()
string str = bs.to_string();
cout<<str<<endl;
//(9)to_ulong()
unsigned long ul = bs.to_ulong();
cout<<ul<<endl;
//(10) cout()方法
cout<<bs.count()<<endl;
system("pause");
return 0;
}*/