Namespaces
Variants

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

From cppreference.net
Utilities library
ヘッダーで定義 <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つのビットセット間でバイナリAND、OR、XORを実行します、 lhs rhs の間で。

1) 対応するビットのペアに対するバイナリAND演算の結果を含む std:: bitset < N > を返します。
2) std:: bitset < N > を返します。これは lhs rhs の対応するビットのペアごとのバイナリORの結果を含みます。
3) 対応するビットのペアごとのバイナリXORの結果を含む std:: bitset < N > を返す。

目次

パラメータ

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を実行
(公開メンバ関数)