cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : bitset : to_ulong
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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 out_of_range exception is thrown.

Example

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

bitset::to_string Convert to string (public member function)
bitset::bitset Construct bitset (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us