C++ bitset to_ullong is used to convert the contents of the bitset to an unsigned long long integer. It returns an unsigned long long with the integer value that has the same bits set as the bitset.
Syntax
Example
unsigned long long to_ullong();
Parameter
It does not take any parameter.
Return value
It returns an Integer value with the same bit representation as the bitset object.
Example 1
Example
#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;
}
Output:
Output
1111 as an integer is : 15
Example 2
Example
#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;
}
Output:
Output
111111 as an integer is : 63