std::bitset<N>::operator<<,<<=,>>,>>=

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
std::bitset
Member types
Member functions
Element access
Capacity
Modifiers
bitset::operator<<=bitset::operator>>=bitset::operator<<bitset::operator>>
Conversions
(哋它亢++11)
Non-member functions
Helper classes
(哋它亢++11)
 
bitset operator<<( std::size_t pos ) const;
(1) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)
bitset& operator<<=( std::size_t pos );
(2) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)
bitset operator>>( std::size_t pos ) const;
(3) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)
bitset& operator>>=( std::size_t pos );
(4) (noexcept since 哋它亢++11)
(constexpr since 哋它亢++23)

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.

Parameters

pos - number of positions to shift the bits

Return value

1,3) New bitset object containing the shifted bits.
2,4) *this

Example

#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)

See also

(哋它亢++20)
computes the result of bitwise left-rotation
(function template)
(哋它亢++20)
computes the result of bitwise right-rotation
(function template)
performs binary AND, OR, XOR and NOT
(public member function)