Namespaces
Variants

std::bitset<N>:: operator&=,|=,^=,~

From cppreference.net
Utilities library
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) 対応するビットのペアに対してバイナリAND演算を行った結果をビットに設定します。 * this other の間で。
2) 対応するビットのペアに対して二進法のOR演算を行った結果をビットに設定します。 * this other の間で。
3) 対応するビットのペアに対するバイナリXORの結果をビットに設定します * this other の間で。
4) すべてのビットが反転された(二進数NOT) * this の一時コピーを返します。

&= |= 、および ^= は、同じサイズ N のビットセットに対してのみ定義されていることに注意してください。

目次

パラメータ

その他 - 別のビットセット

戻り値

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)

関連項目

バイナリ左シフトおよび右シフトを実行する
(公開メンバ関数)