std::bitset<N>::to_ullong

Converts the contents of the bitset to an unsigned long long integer.

# Declarations

unsigned long long to_ullong() const

(since C++11) (constexpr since C++23)

# Return value

The converted integer

# Example

#include <bitset>
#include <iostream>
#include <limits>
 
int main()
{
    std::bitset<std::numeric_limits<unsigned long long>::digits> b
    (
        0x123456789abcdef0LL
    );
 
    std::cout << b << "  " << std::hex << b.to_ullong() << '\n';
    b.flip();
    std::cout << b << "  " << b.to_ullong() << '\n';
 
    std::bitset<std::numeric_limits<unsigned long long>::digits + 1> q{0};
    try
    {
        (~q).to_ullong(); // throws
    }
    catch (const std::overflow_error& ex)
    {
        std::cout << "ex: " << ex.what() << '\n';
    }
}

# See also