stdbitsetto_ulong(3)
std::bitset<N>::to_ulong - std::bitset<N>::to_ulong
Synopsis
unsigned long to_ulong() constConverts the contents of the bitset to an unsigned long integer. The first bit of the bitset corresponds to the least significant digit of the number and the last bit corresponds to the most significant digit.
Parameters
(none)
Return value
the converted integer
Exceptions
throws std::overflow_error if the value can not be represented in unsigned long.
Example
// Run this code
#include <iostream>
#include <bitset>
int main()
{
for (unsigned long i = 0; i < 10; ++i) {
std::bitset<5> b(i);
std::bitset<5> b_inverted = ~b;
std::cout << i << ‘\t’;
std::cout << b << ‘\t’;
std::cout << b_inverted << ‘\t’;
std::cout << b_inverted.to_ulong() << ‘\n’;
}
}
Output:
See also