std::bitset::flip
bitset<N>& flip(); | (1) | |
|---|---|---|
bitset<N>& flip( size_t pos ); | (2) | |
翻转位,即更改true值到false和false值到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不对应于位集中的有效位置。
例
二次
#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';
}二次
产出:
二次
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) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

