Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
bitset
bitset::bitset
bitset operators
member functions:
bitset::any
bitset::count
bitset::flip
bitset::none
bitset::operator[]
bitset::reset
bitset::set
bitset::size
bitset::test
bitset::to_string
bitset::to_ulong


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 overflow_error 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