|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member types | ||||
| Member functions | ||||
(until C++20) | ||||
| Element access | ||||
| Capacity | ||||
| Modifiers | ||||
| Conversions | ||||
bitset::to_ullong (C++11) | ||||
| Non-member functions | ||||
| Helper classes | ||||
(C++11) | ||||
unsignedlonglong to_ullong()const | (since C++11) (constexpr since C++23) | |
Converts the contents of the bitset to anunsignedlonglong 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.
Contents |
(none)
The converted integer
std::overflow_error if the value can not be represented inunsignedlonglong.
#include <bitset>#include <iostream>#include <limits> int main(){std::bitset<std::numeric_limits<unsignedlonglong>::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<unsignedlonglong>::digits+1> q{0};try{(~q).to_ullong();// throws}catch(conststd::overflow_error& ex){std::cout<<"ex: "<< ex.what()<<'\n';}}
Output:
0001001000110100010101100111100010011010101111001101111011110000 123456789abcdef01110110111001011101010011000011101100101010000110010000100001111 edcba9876543210fex: _Base_bitset::_M_do_to_ullong
| returns a string representation of the data (public member function)[edit] | |
| returns anunsignedlong integer representation of the data (public member function)[edit] |