bitset::to_ulong
Converts a bitset object to the integer that would generate the sequence of bits contained if used to initialize the bitset.
unsigned long to_ulong( ) const;
Return Value
An integer that would generate the bits in a bitset if used in the initialization of the bitset.
Remarks
Applying the member function would return the integer that has the same sequence of 1 and 0 digits as is found in sequence of bits contained in the bitset.
The member function throws overflow_error if any bit in the bit sequence has a bit value that cannot be represented as a value of type unsigned long*.*
Example
// bitset_to_ulong.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1 ( 7 );
cout << "The ordered set of bits in the bitset<5> b1( 7 )"
<< "\n that was generated by the number 7 is: ( "
<< b1 << " )" << endl;
unsigned long int i;
i = b1.to_ulong( );
cout << "The integer returned from the bitset b1,"
<< "\n by the member function to_long( ), that"
<< "\n generated the bits as a base two number is: "
<< i << "." << endl;
}
The ordered set of bits in the bitset<5> b1( 7 )
that was generated by the number 7 is: ( 00111 )
The integer returned from the bitset b1,
by the member function to_long( ), that
generated the bits as a base two number is: 7.
Requirements
Header: <bitset>
Namespace: std