The C++ bitset to_ulong function is employed to transform the data within the bitset into an unsigned long integer. It provides an unsigned long integer containing the identical set of bits as the original bitset.
Syntax
Example
unsigned long to_ulong();
Parameter
It does not take any parameter.
Return value
It yields an Integer value that mirrors the bit representation of the bitset object.
Example 1
Example
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<5> b;
b.set();
cout << b << " as an integer is : " << b.to_ulong();
return 0;
}
Output:
Output
11111 as an integer is : 31
Example 2
Example
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<6> b(string("011011"));
b.set();
int a=b.to_ulong();
cout << b << " as an integer is : " << a;
return 0;
}
Output:
Output
111111 as an integer is : 63