首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::bitset::operators

bitset<N> operator<<( std::size_t pos ) const;

(1)

bitset<N>& operator<<=( std::size_t pos );

(2)

bitset<N> operator>>( std::size_t pos ) const;

(3)

bitset<N>& operator>>=( std::size_t pos );

(4)

向左执行二进制移位和向右执行二进制移位。零移入。

1-2%29执行二进制左移。%282%29版本具有破坏性,即执行到当前对象的转换。

3-4%29执行二进制移位右.。%284%29版本具有破坏性,即执行到当前对象的转换。

参数

pos

-

number of positions to shift the bits

返回值

包含移位位的1,3%29新位集对象

2,4%29*this

例外

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
 
int main()
{
    std::bitset<8> b("01110010");
    std::cout << "initial value: " << b << '\n';
 
    while (b.any()) {
        while (!b.test(0)) {
            b >>= 1;
        }
        std::cout << b << '\n';
        b >>= 1;
    }
}

二次

产出:

二次

代码语言:javascript
复制
initial value: 01110010
00111001
00000111
00000011
00000001

二次

另见

operator&=operator|=operator^=operator~

performs binary AND, OR, XOR and NOT (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券