名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 工具庫‎ | bitset
 
 
 
 
定義於標頭檔案 <bitset>
template< std::size_t N >

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

                          const std::bitset<N>& rhs );
(1) (C++11 起無異常丟擲)
(constexpr 自 C++23 起)
template< std::size_t N >

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

                          const std::bitset<N>& rhs );
(2) (C++11 起無異常丟擲)
(constexpr 自 C++23 起)
template< std::size_t N >

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

                          const std::bitset<N>& rhs );
(3) (C++11 起無異常丟擲)
(constexpr 自 C++23 起)

在兩個 bitset,lhsrhs 之間執行二進位制 AND、OR 和 XOR 運算。

1) 返回一個 std::bitset<N>,其中包含對 lhsrhs 相應位對執行二進位制 AND 運算的結果。
2) 返回一個 std::bitset<N>,其中包含對 lhsrhs 相應位對執行二進位制 OR 運算的結果。
3) 返回一個 std::bitset<N>,其中包含對 lhsrhs 相應位對執行二進位制 XOR 運算的結果。

目錄

[編輯] 引數

lhs - 運算子左側的 bitset
rhs - 運算子右側的 bitset

[編輯] 返回值

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
(public member function) [編輯]