c++处理二进制

#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   声明后的变量可以当作类来操作,有数组的性质    & | ^可对变量进行位操作


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章