std::bitset<N>::to_ullong
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::bitset
(until C++20)
bitset::to_ullong
(C++11)
(C++11)
unsigned long long to_ullong() const
(since C++11) (constexpr since C++23)
Converts the contents of the bitset to an unsigned long 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.
[edit] Parameters
(none)
[edit] Return value
The converted integer
[edit] Exceptions
std::overflow_error if the value can not be represented in unsigned long long.
[edit] Example
Run this code
#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'; } }
Output:
0001001000110100010101100111100010011010101111001101111011110000 123456789abcdef0 1110110111001011101010011000011101100101010000110010000100001111 edcba9876543210f ex: _Base_bitset::_M_do_to_ullong