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

std::bitset::flip

bitset<N>& flip();

(1)

bitset<N>& flip( size_t pos );

(2)

翻转位,即更改true值到falsefalse值到true等于对部分或全部位集的逻辑不操作。

1%29翻转所有位数%28相似operator~,但就地%29

2%29在位置翻转位pos...

参数

pos

-

the position of the bit to flip

返回值

*this...

例外

1%29

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

2%29投std::out_of_range如果pos不对应于位集中的有效位置。

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<4> b;
 
    std::cout << b << "\n";
    std::cout << b.flip(0) << '\n';
    std::cout << b.flip(2) << '\n';
    std::cout << b.flip() << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
0000
0001
0101
1010

二次

另见

set

sets bits to true or given value (public member function)

reset

sets bits to false (public member function)

operator&=operator|=operator^=operator~

performs binary AND, OR, XOR and NOT (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券