Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |utility‎ |bitset
       
       
      Utilities library
       
       
      Defined in header<bitset>
      template<std::size_t N>

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

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

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

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

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

                               conststd::bitset<N>& rhs);
      (3)(noexcept since C++11)
      (constexpr since C++23)

      Performs binary AND, OR, and XOR between two bitsets,lhs andrhs.

      1) Returns astd::bitset<N> containing the result of binary AND on corresponding pairs of bits oflhs andrhs.
      2) Returns astd::bitset<N> containing the result of binary OR on corresponding pairs of bits oflhs andrhs.
      3) Returns astd::bitset<N> containing the result of binary XOR on corresponding pairs of bits oflhs andrhs.

      Contents

      [edit]Parameters

      lhs - the bitset on the left-hand side of the operator
      rhs - the bitset on the right-hand side of the operator

      [edit]Return value

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

      [edit]Example

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

      Output:

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

      [edit]See also

      performs binary AND, OR, XOR and NOT
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/bitset/operator_logic2&oldid=171736"

      [8]ページ先頭

      ©2009-2025 Movatter.jp