C++位集to_ullong()用于将位集的内容转换为无符号的long long整数。它返回一个无符号long long,其整数值与该位集设置的位相同。
unsigned long long to_ullong();
它返回一个与位集对象具有相同位表示形式的Integer值。
#include <iostream> #include <bitset> using namespace std; int main() { bitset<4> b; b.set(); cout << b << " as an integer is : " << b.to_ullong(); return 0; }
输出:
1111 as an integer is : 15
#include <iostream> #include <bitset> using namespace std; int main() { bitset<6> b(string("001100")); b.set(); int a=b.to_ullong(); cout << b << " as an integer is : " << a; return 0; }
输出:
111111 as an integer is : 63
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)