std::bitset<N>::operator<<,<<=,>>,>>=
來自 cppreference.com
bitset operator<<( std::size_t pos ) const; |
(1) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset& operator<<=( std::size_t pos ); |
(2) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset operator>>( std::size_t pos ) const; |
(3) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
bitset& operator>>=( std::size_t pos ); |
(4) | (C++11 起無異常丟擲) (C++23 起為 constexpr) |
執行二進位制左移(向更高索引位置)和二進位制右移(向更低索引位置)。零被移入,超出範圍的位被丟棄(忽略)。
1,2) 執行二進位制左移。(2) 版本是破壞性的,即對當前物件執行移位。
3,4) 執行二進位制右移。(4) 版本是破壞性的,即對當前物件執行移位。
目錄 |
[編輯] 引數
pos | - | 位移位的位數 |
[編輯] 返回值
1,3) 包含移位位的新 bitset 物件。
2,4) *this
[編輯] 示例
執行此程式碼
#include <bitset> #include <iostream> int main() { std::bitset<8> b{0b01110010}; std::cout << b << " (initial value)\n"; for (; b.any(); b >>= 1) { while (!b.test(0)) b >>= 1; std::cout << b << '\n'; } std::cout << b << " (final value)\n"; }
輸出
01110010 (initial value) 00111001 00000111 00000011 00000001 00000000 (final value)
[編輯] 參閱
(C++20) |
計算按位左旋的結果 (函式模板) |
(C++20) |
計算位右旋的結果 (函式模板) |
執行二進位制 AND、OR、XOR 和 NOT (公共成員函式) |