bitset::to_ulong


public member function
unsigned long to_ulong ( ) const;

Convert to unsigned long integer

Returns an unsigned long with the integer value that has the same bits set as the bitset.

Parameters

none

Return value

Integer value with the same bits set as the bitset.

If the bitset is too long to be represented as an unsigned long, an out_of_range exception is thrown.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// bitset::to_ulong
#include <iostream>
#include <bitset>
using namespace std;

int main ()
{
  bitset<4> mybits;     // mybits: 0000

  mybits.set();         // mybits: 1111

  cout << mybits << " as an integer is: " << mybits.to_ulong() << endl;

  return 0;
}


Output:
1111 as an integer is: 15


See also