C++ Bitset Library - to_ulong() Function



Declaration

Following is the declaration for std::bitset::to_ulong() function form std::bitset header.

C++98

 unsigned long to_ulong() const; 

Parameters

None

Return value

Returns bitset as unsigned long number.

Exceptions

No change in bitset if exception is thrown.

Example

The following example shows the usage of std::bitset::to_ulong() function.

 #include <iostream> #include <bitset> #include <typeinfo> using namespace std; int main(void) { bitset<4> b("1010");; auto result = b.to_ulong(); cout << "Decimal representation of " << b << " = " << result << endl; return 0; } 

Let us compile and run the above program, this will produce the following result −

 Decimal representation of 1010 = 10 
bitset.htm
Advertisements