命名空间
变体
操作

std::bitset<N>::to_ullong

来自 cppreference.cn
< cpp‎ | 工具库‎ | bitset
 
 
 
 
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 整型表示
(公共成员函数) [编辑]