C++ to_ullong()
C++ to_ullong()函数
C++ to_ullong()用于将 的内容转换为无符号的long long整数。它会返回一个无符号long long,其整数值与 的位设置相同。
语法
unsigned long long to_ullong();
参数
不带任何参数。
返回值
它返回一个整数值与 对象具有相同的位表示形式。
示例1
#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
示例2
#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