Namespaces
Variants

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

From cppreference.net
Utilities library
Definiert in Header <bitset>
template < std:: size_t N >

std:: bitset < N > operator & ( const std:: bitset < N > & lhs,

const std:: bitset < N > & rhs ) ;
(1) (noexcept seit C++11)
(constexpr seit C++23)
template < std:: size_t N >

std:: bitset < N > operator | ( const std:: bitset < N > & lhs,

const std:: bitset < N > & rhs ) ;
(2) (noexcept seit C++11)
(constexpr seit C++23)
template < std:: size_t N >

std:: bitset < N > operator ^ ( const std:: bitset < N > & lhs,

const std:: bitset < N > & rhs ) ;
(3) (noexcept seit C++11)
(constexpr seit C++23)

Führt binäres UND, ODER und XOR zwischen zwei Bitsätzen aus, lhs und rhs .

1) Gibt ein std:: bitset < N > zurück, das das Ergebnis der binären UND-Operation auf entsprechenden Bitpaaren von lhs und rhs enthält.
2) Gibt ein std:: bitset < N > zurück, das das Ergebnis der binären ODER-Operation auf entsprechenden Bitpaaren von lhs und rhs enthält.
3) Gibt ein std:: bitset < N > zurück, das das Ergebnis der binären XOR-Operation auf entsprechenden Bitpaaren von lhs und rhs enthält.

Inhaltsverzeichnis

Parameter

lhs - das Bitset auf der linken Seite des Operators
rhs - das Bitset auf der rechten Seite des Operators

Rückgabewert

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

Beispiel

#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';
}

Ausgabe:

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

Siehe auch

führt binäres UND, ODER, XOR und NOT aus
(öffentliche Elementfunktion)