c++ std::bitset
转载自 作用:
及 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的更多相关文章
- 记录一个比较少用的容器C++ std::bitset
bitset存储二进制数位. bitset就像一个bool类型的数组一样,但是有空间优化——bitset中的一个元素一般只占1 bit,相当于一个char元素所占空间的八分之一. bitset中的每个 ...
- DFS序+线段树+bitset CF 620E New Year Tree(圣诞树)
题目链接 题意: 一棵以1为根的树,树上每个节点有颜色标记(<=60),有两种操作: 1. 可以把某个节点的子树的节点(包括本身)都改成某种颜色 2. 查询某个节点的子树上(包括本身)有多少个不 ...
- 把《c++ primer》读薄(3-3 标准库bitset类型)
督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. //开头 #include <bitset> using std::bitset; 问题1.标准库bitset类型( ...
- (DFS、bitset)AOJ-0525 Osenbei
题目地址 简要题意: 给出n行m列的0.1矩阵,每次操作可以将任意一行或一列反转,即这一行或一列中0变为1,1变为0.问通过任意多次这样的变换,最多可以使矩阵中有多少个1. 思路分析: 行数比较小,先 ...
- 【状压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)) ...
- Bitset 用法(STL)
std::bitset是STL的一个模板类,它的参数是整形的数值,使用位的方式和数组区别不大,相当于只能存一个位的数组.下面看一个例子 bitset<20> b1(5); cout< ...
- bitset常用函数用法记录 (转载)
有些程序要处理二进制位的有序集,每个位可能包含的是0(关)或1(开)的值.位是用来保存一组项或条件的yes/no信息(有时也称标志)的简洁方法.标准库提供了bitset类使得处理位集合更容易一些.要使 ...
- bzoj 3687 bitset的运用
题目大意: 小呆开始研究集合论了,他提出了关于一个数集四个问题:1. 子集的异或和的算术和.2. 子集的异或和的异或和.3. 子集的算术和的算术和.4. 子集的算术和的异或和.目前为止,小呆已经解决了 ...
- 标准非STL之bitset
template <size_t N> class bitset; BitsetA bitset stores bits (elements with only two possible ...
随机推荐
- PAT1014——福尔摩斯的约会
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”.大侦探很快就明白了,字条 ...
- 五、PackageManager获取版本号
PackageInfo代表的是关于一个包的所有信息,就相当于一个APP应用的清单文件中收集到的所有信息. 通过这个类我们就可以获取类似版本号等一些信息. 1 2 3 4 5 6 7 8 9 10 11 ...
- CSS之Generator
这个工具可以,收藏一下.CSS Generator
- 很全的corel图像分类,场景识别图像库
这是真正的Corel-5K图像集,共包含科雷尔(Corel)公司收集整理的5000幅图片,故名:Corel-5K,童鞋们可用于科学图像实验:分类.检索等.Corel-5k数据集是图像实验的事实标准数据 ...
- Android webkit 事件传递流程详解
前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...
- SQL学习备忘
1.按照拼音首字母的正序或倒序排序 SELECT CREATOR_REALNAME FROM tableName ORDER BY NLSSORT(CREATOR_REALNAME, 'NLS_SOR ...
- Android实现Http协议案例
在Android开发中,使用Http协议实现网络之间的通信是随处可见的,使用http方式主要采用2中请求方式即get和post两种方式. 一.使用get方式: HttpGet httpGet = ne ...
- sicily 1022. Train Problem
本题主要是出栈入栈顺序的问题 Home Problems My Status Standing <-> 1022. Train Problem Total: 2 ...
- MVC5_学习笔记_1_CodeFirst
MVC5_EF6_1/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Author: Nicolas Hery - ...
- 【Qt】Qt之Tab键切换焦点顺序【转】
简介 Qt的窗口部件按用户的习惯来处理键盘焦点.也就是说,其出发点是用户的焦点能定向到任何一个窗口,或者窗口中任何一个部件. 焦点获取方式比较多,例如:鼠标点击.Tab键切换.快捷键.鼠标滚轮等. 习 ...