首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::bitset::to_ulong

unsigned long to_ulong() const

?

?

将位集的内容转换为unsigned long整数。

该位集的第一位对应于所述数字的最小有效位数,而所述最后一位对应于所述最有效位数。

参数

%280%29

返回值

转换的整数。

例外

抛出std::overflow_error如果值不能表示为unsigned long...

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
 
int main()
{
    for (unsigned long i = 0; i < 10; ++i) {
        std::bitset<5> b(i);
        std::bitset<5> b_inverted = ~b;
        std::cout << i << '\t';
        std::cout << b << '\t';
        std::cout << b_inverted << '\t';
        std::cout << b_inverted.to_ulong() << '\n'; 
    }
}

二次

产出:

二次

代码语言:javascript
复制
0        00000        11111        31
1        00001        11110        30
2        00010        11101        29
3        00011        11100        28
4        00100        11011        27
5        00101        11010        26
6        00110        11001        25
7        00111        11000        24
8        01000        10111        23
9        01001        10110        22

二次

另见

to_string

returns a string representation of the data (public member function)

to_ullong (C++11)

returns an unsigned long long integer representation of the data (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com