转载自

作用:
及  64位 移位  取或  用64个位存储64个位,取 或 merge 。 然后查索引即知道id是否存在~~ 目标:省空间。
#include <iostream>
#include <bitset>
#include <string>
using namespace std; int main(){ //bitset<n> b;//b有n位,每位都为0
bitset<> bitvec;
cout << bitvec << endl; //bitset<n> b(u); //b是unsigned long型u的一个副本
bitset<> bitvec2(0xffff);
cout << bitvec2 << endl; bitset<> bitvec3(0xffff);
cout << bitvec3 << endl; //bitset<n> b(s); //b是string对象s中含有的位串的副本
string strval("");
bitset<> bitvec4(strval);
cout << bitvec4 << endl; string str("");
//bitset<n> b(s, pos, n);//b是s中从位置pos开始的n个位的副本
bitset<> bitvec5(str, , );
cout << bitvec5 << endl;
bitset<> bitvec6(str, str.size() - );
cout << bitvec6 << endl; cout << sizeof(unsigned long) << endl; //unsigned long a = 1;
//unsigned long b = a << 63;
uint64_t a = ;
uint64_t b = a << ;
bitset<> vec(b);
cout << vec << endl;
return ;
} output: 0000000000000000 16
1111111111111111 16
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111 128
00000000000000000000000000001100 32
00000000000000000000000000001100 32
00000000000000000000000000001101 32
8 1
1000000000000000000000000000000000000000000000000000000000000000 64


-------------------------------------------

#include <iostream>
#include <stdint.h>
#include <bitset>
using namespace std; int main() {
    for(int i=0; i<64; i++){
        uint64_t a = 1;
        uint64_t b = a << i;
        bitset<64> bs(b);
        cout << i << " \t" << bs << "," << bs.to_ulong() << endl;
    }
    bitset<64> sum_bin;
    sum_bin.set();
    cout << "\t" << sum_bin << "," << sum_bin.to_ulong() << endl;     return 0;
} 0     0000000000000000000000000000000000000000000000000000000000000001,1
1     0000000000000000000000000000000000000000000000000000000000000010,2
2     0000000000000000000000000000000000000000000000000000000000000100,4
3     0000000000000000000000000000000000000000000000000000000000001000,8
4     0000000000000000000000000000000000000000000000000000000000010000,16
5     0000000000000000000000000000000000000000000000000000000000100000,32
6     0000000000000000000000000000000000000000000000000000000001000000,64
7     0000000000000000000000000000000000000000000000000000000010000000,128
8     0000000000000000000000000000000000000000000000000000000100000000,256
9     0000000000000000000000000000000000000000000000000000001000000000,512
10     0000000000000000000000000000000000000000000000000000010000000000,1024
11     0000000000000000000000000000000000000000000000000000100000000000,2048
12     0000000000000000000000000000000000000000000000000001000000000000,4096
13     0000000000000000000000000000000000000000000000000010000000000000,8192
14     0000000000000000000000000000000000000000000000000100000000000000,16384
15     0000000000000000000000000000000000000000000000001000000000000000,32768
16     0000000000000000000000000000000000000000000000010000000000000000,65536
17     0000000000000000000000000000000000000000000000100000000000000000,131072
18     0000000000000000000000000000000000000000000001000000000000000000,262144
19     0000000000000000000000000000000000000000000010000000000000000000,524288
20     0000000000000000000000000000000000000000000100000000000000000000,1048576
21     0000000000000000000000000000000000000000001000000000000000000000,2097152
22     0000000000000000000000000000000000000000010000000000000000000000,4194304
23     0000000000000000000000000000000000000000100000000000000000000000,8388608
24     0000000000000000000000000000000000000001000000000000000000000000,16777216
25     0000000000000000000000000000000000000010000000000000000000000000,33554432
26     0000000000000000000000000000000000000100000000000000000000000000,67108864
27     0000000000000000000000000000000000001000000000000000000000000000,134217728
28     0000000000000000000000000000000000010000000000000000000000000000,268435456
29     0000000000000000000000000000000000100000000000000000000000000000,536870912
30     0000000000000000000000000000000001000000000000000000000000000000,1073741824
31     0000000000000000000000000000000010000000000000000000000000000000,2147483648
32     0000000000000000000000000000000100000000000000000000000000000000,4294967296
33     0000000000000000000000000000001000000000000000000000000000000000,8589934592
34     0000000000000000000000000000010000000000000000000000000000000000,17179869184
35     0000000000000000000000000000100000000000000000000000000000000000,34359738368
36     0000000000000000000000000001000000000000000000000000000000000000,68719476736
37     0000000000000000000000000010000000000000000000000000000000000000,137438953472
38     0000000000000000000000000100000000000000000000000000000000000000,274877906944
39     0000000000000000000000001000000000000000000000000000000000000000,549755813888
40     0000000000000000000000010000000000000000000000000000000000000000,1099511627776
41     0000000000000000000000100000000000000000000000000000000000000000,2199023255552
42     0000000000000000000001000000000000000000000000000000000000000000,4398046511104
43     0000000000000000000010000000000000000000000000000000000000000000,8796093022208
44     0000000000000000000100000000000000000000000000000000000000000000,17592186044416
45     0000000000000000001000000000000000000000000000000000000000000000,35184372088832
46     0000000000000000010000000000000000000000000000000000000000000000,70368744177664
47     0000000000000000100000000000000000000000000000000000000000000000,140737488355328
48     0000000000000001000000000000000000000000000000000000000000000000,281474976710656
49     0000000000000010000000000000000000000000000000000000000000000000,562949953421312
50     0000000000000100000000000000000000000000000000000000000000000000,1125899906842624
51     0000000000001000000000000000000000000000000000000000000000000000,2251799813685248
52     0000000000010000000000000000000000000000000000000000000000000000,4503599627370496
53     0000000000100000000000000000000000000000000000000000000000000000,9007199254740992
54     0000000001000000000000000000000000000000000000000000000000000000,18014398509481984
55     0000000010000000000000000000000000000000000000000000000000000000,36028797018963968
56     0000000100000000000000000000000000000000000000000000000000000000,72057594037927936
57     0000001000000000000000000000000000000000000000000000000000000000,144115188075855872
58     0000010000000000000000000000000000000000000000000000000000000000,288230376151711744
59     0000100000000000000000000000000000000000000000000000000000000000,576460752303423488
60     0001000000000000000000000000000000000000000000000000000000000000,1152921504606846976
61     0010000000000000000000000000000000000000000000000000000000000000,2305843009213693952
62     0100000000000000000000000000000000000000000000000000000000000000,4611686018427387904
63     1000000000000000000000000000000000000000000000000000000000000000,9223372036854775808
     1111111111111111111111111111111111111111111111111111111111111111,18446744073709551615

c++ std::bitset的更多相关文章

  1. 记录一个比较少用的容器C++ std::bitset

    bitset存储二进制数位. bitset就像一个bool类型的数组一样,但是有空间优化——bitset中的一个元素一般只占1 bit,相当于一个char元素所占空间的八分之一. bitset中的每个 ...

  2. DFS序+线段树+bitset CF 620E New Year Tree(圣诞树)

    题目链接 题意: 一棵以1为根的树,树上每个节点有颜色标记(<=60),有两种操作: 1. 可以把某个节点的子树的节点(包括本身)都改成某种颜色 2. 查询某个节点的子树上(包括本身)有多少个不 ...

  3. 把《c++ primer》读薄(3-3 标准库bitset类型)

    督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. //开头 #include <bitset> using std::bitset; 问题1.标准库bitset类型( ...

  4. (DFS、bitset)AOJ-0525 Osenbei

    题目地址 简要题意: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以使矩阵中有多少个1. 思路分析: 行数比较小,先 ...

  5. 【状压dp】【bitset】bzoj1688 [Usaco2005 Open]Disease Manangement 疾病管理

    vs(i)表示患i这种疾病的牛的集合. f(S)表示S集合的病被多少头牛患了. 枚举不在S中的疾病i,把除了i和S之外的所有病的牛集合记作St. f(S|i)=max{f(S)+((St|vs(i)) ...

  6. Bitset 用法(STL)

    std::bitset是STL的一个模板类,它的参数是整形的数值,使用位的方式和数组区别不大,相当于只能存一个位的数组.下面看一个例子 bitset<20> b1(5); cout< ...

  7. bitset常用函数用法记录 (转载)

    有些程序要处理二进制位的有序集,每个位可能包含的是0(关)或1(开)的值.位是用来保存一组项或条件的yes/no信息(有时也称标志)的简洁方法.标准库提供了bitset类使得处理位集合更容易一些.要使 ...

  8. bzoj 3687 bitset的运用

    题目大意: 小呆开始研究集合论了,他提出了关于一个数集四个问题:1. 子集的异或和的算术和.2. 子集的异或和的异或和.3. 子集的算术和的算术和.4. 子集的算术和的异或和.目前为止,小呆已经解决了 ...

  9. 标准非STL之bitset

    template <size_t N> class bitset; BitsetA bitset stores bits (elements with only two possible ...

随机推荐

  1. DWZ 验证 CLASS 规则

     验证:格式  class="XXXX" 即可验证. required: "必填字段",  remote: "请修正该字段",  email ...

  2. 关于offsetWidth,clientWidth,与jquery的width()方法

    offsetWidth包括了边框的宽度, clientWidth只是元素的宽度, 当元素的"display"属性为“none”的时候,用offsetWidth(clientWidt ...

  3. 20141128—JavaScript对象

    JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... String 对象的 length 属性来获得字符串的长度: var message="Hello World!& ...

  4. 3月3日 Mark

    感觉LeetCode OJ 水题较多... 不过回复基础就是这样吧.. 刚刚和Gaewah聊了下,后续可以考虑去做Topcoder的SRM或者codeforces,Mark.

  5. c++11:copy_n

    copy_n: Copies exactly count values from the range beginning at first to the range beginning at resu ...

  6. php中的in_array分析及其替换方法

    php中的in_array函数效率分析 http://www.jb51.net/article/41446.htm http://www.server110.com/php/201309/1150.h ...

  7. javascript对象与实例

    var person=new Object(); var person2={}; 一切都是对象 person是Object的实例, 也是对象. 第二个person2也是如此,只不过它是采用字面量的方式 ...

  8. WPF中XAML转义字符

    字符 转义字符 备注 & (ampersand) & 这个没什么特别的,几乎所有的地方都需要使用转义字符 > (greater-than character) > 在属性( ...

  9. jquery弹出关闭遮罩层实例

    jquery弹出关闭遮罩层实例. 代码如下: <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" & ...

  10. apache 多站点搭建

    一.apache配置多站点方法一 1.首先修改apache httpd.conf 文件 启用虚拟主机组件功能 取消 LoadModule vhost_alias_module modules/mod_ ...