std::bitset<N>::operator&=,|=,^=,~
From cppreference.com
bitset& operator&=( const bitset& other ); |
(1) | (C++11 以降 noexcept) (C++23 以降 constexpr) |
bitset& operator|=( const bitset& other ); |
(2) | (C++11 以降 noexcept) (C++23 以降 constexpr) |
bitset& operator^=( const bitset& other ); |
(3) | (C++11 以降 noexcept) (C++23 以降 constexpr) |
bitset operator~() const; |
(4) | (C++11 以降 noexcept) (C++23 以降 constexpr) |
バイナリAND、OR、XOR、NOTを実行します。
1) *thisとotherの対応するビットペアに対するバイナリANDの結果をビットに設定します。
2) *thisとotherの対応するビットペアに対するバイナリORの結果をビットに設定します。
3) *thisとotherの対応するビットペアに対するバイナリXORの結果をビットに設定します。
4) すべてのビットを反転した(バイナリNOT)*thisの一時的なコピーを返します。
&=、|=、^=は、同じサイズNのbitsetに対してのみ定義されることに注意してください。
目次 |
[編集] パラメータ
| その他 | - | 別のbitset |
[編集] 戻り値
1-3) *this
4) std::bitset<N>(*this).flip()
[編集] 例
このコードを実行
#include <bitset> #include <cstddef> #include <iostream> #include <string> int main() { const std::string pattern_str{"1001"}; std::bitset<16> pattern{pattern_str}, dest; for (std::size_t i = dest.size() / pattern_str.size(); i != 0; --i) { dest <<= pattern_str.size(); dest |= pattern; std::cout << dest << " (i = " << i << ")\n"; } std::cout << ~dest << " (~dest)\n"; }
出力
0000000000001001 (i = 4) 0000000010011001 (i = 3) 0000100110011001 (i = 2) 1001100110011001 (i = 1) 0110011001100110 (~dest)
[編集] 関連項目
| ビット単位の左シフトと右シフトを実行する (public member function) |