在C++STL中提供了位图的库bitset类,下面记录一下bitset的使用
template <size_t N> class bitset;
//N: Number of bits to contain
构造函数
(1)bitset ( );//空的,默认设置为0
(2)bitset ( unsigned long val );
(3)参数可以使字符串,
使用:
// constructing bitsets
#include <iostream>
#include <string>
#include <bitset>
using namespace std;
int main ()
{
bitset<10> first; // empty bitset
bitset<10> second (120ul); // initialize from unsigned long
bitset<10> third (string("01011")); // initialize from string
cout << first << endl; // 00000 00000
cout << second << endl;