📜  C++ STL-bitset.to_ullong()函数

📅  最后修改于: 2020-10-17 06:36:28             🧑  作者: Mango

C++ STL bitset.to_ullong()函数

C++ STL bitset.to_ullong()用于将位集的内容转换为无符号的long long整数。它返回一个无符号long long,其整数值与该位集设置的位相同。

句法

unsigned long long to_ullong();

参数

它不带任何参数。

返回值

它返回一个与位集对象具有相同位表示形式的Integer值。

例子1

#include 
#include 
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 
#include 
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