std::bitset<N>::to_ullong
來自 cppreference.com
unsigned long long to_ullong() const |
(C++11 起) (C++23 起為 constexpr) |
|
將 bitset 的內容轉換為 unsigned long long 整數。
bitset 的第一位對應於數字的最低有效位,最後一位對應於最高有效位。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
轉換後的整數。
[編輯] 異常
如果該值無法用 unsigned long long 表示,則丟擲 std::overflow_error。
[編輯] 示例
執行此程式碼
#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'; } }
輸出
0001001000110100010101100111100010011010101111001101111011110000 123456789abcdef0 1110110111001011101010011000011101100101010000110010000100001111 edcba9876543210f ex: _Base_bitset::_M_do_to_ullong
[編輯] 參閱
返回資料的字串表示 (公共成員函式) | |
返回資料的 unsigned long 整型表示 (公共成員函式) |