std::bitset::to_ullong(3)
π
std::bitset::to_ullong β the NAME section, bestie
ok so this page is std::bitset::to_ullong from the C++ Standard Library, and honestly? it's giving "glow-up for your bits." π¦
β¨ Synopsis β¨
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. Periodt. π₯
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. So likeβ¦ read it backwards in your head, it's fine, we've all been there. π«Ά
π Parameters π
(none)
Nothing. Zero. Nada. Not a single argument, she takes no notes. π
β Return value β
The converted integer. That's it, that's the whole vibe. β¨
π Exceptions π
std::overflow_errorif the value can not be represented inunsigned long long.
fr fr, if your bitset is too big for an unsigned long long to hold, she's gonna throw. No cap. Don't say I didn't warn you. π
πΈ 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
likeβ¦ look at her go. b.flip() said "new bits, who dis" and the whole number changed. iconic behavior honestly. π
π See also π
to_stringβ returns a string representation of the data (public member function)to_ulongβ returns an unsignedlonginteger representation of the data (public member function)
ok that's the whole page bestie, go forth and convert your bits responsibly π
source/version + date drop, since you gotta cite your sources even when you're cute: straight fromhttp://cppreference.com, the2024.06.10edition. mwah. ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms