flip
语法:
1 2 |
bitset &flip(); bitset &flip( size_t pos ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/**源代码?????? *? @brief Toggles every bit to its opposite value.????? */????? bitset<_Nb>&????? flip()????? {??????? this->_M_do_flip();??????? this->_M_do_sanitize();??????? return *this; }???? /**?????? *? @brief Toggles a given bit to its opposite value.?????? *? @param? position? The index of the bit.?????? *? @throw? std::out_of_range? If @a pos is bigger the size of the %set.????? */????? bitset<_Nb>&????? flip(size_t __position)????? { if (__position >= _Nb)????? __throw_out_of_range(__N("bitset::flip"));??????? return _Unchecked_flip(__position);????? } |
flip()函数反置bitset中所有的位,即将1设为0,0设为1。如果指定pos,那么只有pos上的位被反置。
注:flip()和~操作符都是翻转全部位。
测试代码:
运行结果:
10000010
翻转全部位:
10000010
10000010
翻转全部位:
10000010
10000111
翻转第5位:
10100111
请按任意键继续. . .