码迷,mamicode.com
首页 > 编程语言 > 详细

c++ std::bitset

时间:2015-06-26 17:33:02      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/qll125596718/article/details/6901935


#include <iostream>
#include <stdint.h>
#include <bitset>
using namespace std;


int main() {
    for(uint64_t i=0; i<64; i++){
       bitset<64> bs;
       //uint64_t j = (uint64_t)1 << i;
       bs.set(i);
       cout << i << ": " << bs << "," << bs.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

 

c++ std::bitset

标签:

原文地址:http://www.cnblogs.com/i80386/p/4602546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!