bitset语法

1 构造函数 bitset<size> name (string)       size为数组大小 string为10字符串 默认前面补零(需要注意的是如果填入数字会将其转化为二进制形式)并且 size小于string(int)的时候 int取后size部分 string取前size部分

2 bitset可以直接用位运算符进行运算 并且 bitset左移右移的时候 按方向补0

3 常用函数

   cout << foo.count() << endl;  //5  (count函数用来求bitset中1的位数,foo中共有5个1
    cout << foo.size() << endl;   //8  (size函数用来求bitset的大小,一共有8位

    cout << foo.test(0) << endl;  //true  (test函数用来查下标处的元素是0还是1,并返回false或true,此处foo[0]为1,返回true
    cout << foo.test(2) << endl;  //false  (同理,foo[2]为0,返回false

    cout << foo.any() << endl;  //true  (any函数检查bitset中是否有1
    cout << foo.none() << endl;  //false  (none函数检查bitset中是否没有1
    cout << foo.all() << endl;  //false  (all函数检查bitset中是全部为1


posted @ 2021-07-09 14:34  旅玖旅玖  阅读(58)  评论(0编辑  收藏  举报