Namespaces
Variants

operator&,|,^(std::bitset)

ja.cppreference.net から
 
 
ユーティリティライブラリ
言語サポート
型サポート (基本型、RTTI)
ライブラリ機能テストマクロ (C++20)
プログラムユーティリティ
可変長引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)    
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)(C++20)(C++20)    
(C++20)
swap および 型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
共通の語彙型
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
ヘッダ <bitset>
template< std::size_t N >
std::bitset<N> operator&( const std::bitset<N>& lhs,
                          const std::bitset<N>& rhs );
で定義 (1) (C++11からnoexcept)
(C++23からconstexpr)
template< std::size_t N >
std::bitset<N> operator|( const std::bitset<N>& lhs,
                          const std::bitset<N>& rhs );
(2) (C++11からnoexcept)
(C++23からconstexpr)
template< std::size_t N >
std::bitset<N> operator^( const std::bitset<N>& lhs,
                          const std::bitset<N>& rhs );
(3) (C++11からnoexcept)
(C++23からconstexpr)

2つのビットセット lhs と rhs の間で、バイナリAND、OR、XORを実行します。

1) std::bitset<N> と lhs の対応するビットの組に対するバイナリANDの結果を含む rhs を返します。
2) std::bitset<N> と lhs の対応するビットの組に対するバイナリORの結果を含む rhs を返します。
3) std::bitset<N> と lhs の対応するビットの組に対するバイナリXORの結果を含む rhs を返します。

パラメータ

lhs - 演算子の左側のビットセット
rhs - 演算子の右側のビットセット

戻り値

1) std:: bitset < N > ( lhs ) & = rhs
2) std:: bitset < N > ( lhs ) | = rhs
3) std:: bitset < N > ( lhs ) ^ = rhs

例

#include <bitset>
#include <iostream>
int main()
{
    std::bitset<4> b1("0110");
    std::bitset<4> b2("0011");
    std::cout << "b1 & b2: " << (b1 & b2) << '\n';
    std::cout << "b1 | b2: " << (b1 | b2) << '\n';
    std::cout << "b1 ^ b2: " << (b1 ^ b2) << '\n';
}

出力:

b1 & b2: 0010
b1 | b2: 0111
b1 ^ b2: 0101

関連項目

二項AND、OR、XORおよびNOTを実行
(公開メンバ関数)