在线文档教程
C++
应用 | Utilities

operators (std::bitset)

运算符&,,^%28std::位集%29

template< std::size_t N > bitset operator&( const bitset& lhs, const bitset& rhs (1)
template< std::size_t N > bitset<N> operator|( const bitset<N>& lhs, const bitset<N>& rhs (2)
template< std::size_t N > bitset<N> operator^( const bitset<N>& lhs, const bitset<N>& rhs (3)

在两个位集之间执行二进制和、OR和XOR,lhsrhs...

1%29bitset<N>包含二进制结果和相应的位对的lhs和rhs...

2%29bitset<N>的对应位对上的二进制或的结果。lhs和rhs...

3%29bitset<N>的对应位对上包含二进制异或的结果。lhs和rhs...

参数

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

返回值

1%29bitset<N>(lhs) &= rhs

2%29bitset<N>(lhs) |= rhs

3%29bitset<N>(lhs) ^= rhs

例外

(none)(until C++11)
noexcept specification: noexcept(since C++11)

二次

#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

二次

另见

operator&=operator|=operator^=operator~performs binary AND, OR, XOR and NOT (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/实用程序/位集/操作符[医]逻辑2