您的位置:首页 > 其它

bitset二

2016-01-12 13:36 148 查看
#include <iostream>
#include <string>
#include <bitset>

using namespace std;

int main ()
{
bitset<32> a(132);
cout << a << endl;

bool is_set = a.any();   // any检查a里边至少有一个为1,则为true,
if(is_set)
cout << "a里边至少有一个为1:" << endl;

bool is_not_set = a.none();  // a里边一个1都没有
if(is_not_set)
cout << "a里边一个1都没有:" << endl;

size_t bits_set = a.count();
cout << "a里一共有 " << bits_set << "个1。" << endl;

cout << "a的大小 " << a.size() << endl;

cout << "a 里有:" << a.size() - a.count() << "个0。" << endl;

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: