std::bitset<N>::operator&=,|=,^=,~
來自 cppreference.com
bitset& operator&=( const bitset& other ); |
(1) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset& operator|=( const bitset& other ); |
(2) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset& operator^=( const bitset& other ); |
(3) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset operator~() const; |
(4) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
執行二進位制 AND、OR、XOR 和 NOT。
1) 將位設定為 *this 和 other 相應位對的二進位制 AND 結果。
2) 將位設定為 *this 和 other 相應位對的二進位制 OR 結果。
3) 將位設定為 *this 和 other 相應位對的二進位制 XOR 結果。
4) 返回 *this 的臨時副本,其中所有位都已翻轉(二進位制 NOT)。
請注意,`&=`, `|=` 和 `^=` 僅對大小 `N` 相同的 bitset 有定義。
目錄 |
[編輯] 引數
其他 | - | 另一個 bitset |
[編輯] 返回值
1-3) *this
4) std::bitset<N>(*this).flip()
[編輯] 示例
執行此程式碼
#include <bitset> #include <cstddef> #include <iostream> #include <string> int main() { const std::string pattern_str{"1001"}; std::bitset<16> pattern{pattern_str}, dest; for (std::size_t i = dest.size() / pattern_str.size(); i != 0; --i) { dest <<= pattern_str.size(); dest |= pattern; std::cout << dest << " (i = " << i << ")\n"; } std::cout << ~dest << " (~dest)\n"; }
輸出
0000000000001001 (i = 4) 0000000010011001 (i = 3) 0000100110011001 (i = 2) 1001100110011001 (i = 1) 0110011001100110 (~dest)
[編輯] 參閱
執行二進位制左移和右移 (public 成員函式) |