std::bitset<N>::operator<<,<<=,>>,>>=
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::bitset
(until C++20)
bitset::operator<<=bitset::operator>>=bitset::operator<<bitset::operator>>
(C++11)
(C++11)
Performs binary shift left (towards higher index positions) and binary shift right (towards lower index positions). Zeroes are shifted in, and bits that would go to an index out of range are dropped (ignored).
1,2) Performs binary shift left. The (2) version is destructive, i.e. performs the shift to the current object.
3,4) Performs binary shift right. The (4) version is destructive, i.e. performs the shift to the current object.
Contents
[edit] Parameters
pos
-
number of positions to shift the bits
[edit] Return value
1,3) New bitset object containing the shifted bits.
2,4) *this
[edit] Example
Run this code
#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"; }
Output:
01110010 (initial value) 00111001 00000111 00000011 00000001 00000000 (final value)