#include <iostream>
#include <bitset>
#include <string>
using namespace std;
int main()
{
bitset<32> a;
cout << a << endl;
bitset<16> b(0xffff);
cout << b << endl;
bitset<32> c(0xffff);
cout << c << endl;
bitset<32> d(156);
cout << d << endl;
string str("10101011000001100010"); //從第五位開始取四個
bitset<32> f(str,5,4);
cout << f << endl;
bitset<32> g(str, str.size() - 4); //從倒數第四位開始取數
cout << g << endl;
return 0;
}
bitset<num> name 聲明後的變量可以當作類來操作,有數組的性質 & | ^可對變量進行位操作