稳定盈利的期货交易方法-量化趋势交易

alantop -专业量化投资者

爱好:量化投资,逆向工程,渗透
随笔 - 595, 文章 - 0, 评论 - 921, 引用 - 0
数据加载中……

bitset::flip的含义和用法:

bitset::flip:反转所有位,或者指定的位。

Toggles the value of all the bits in a bitset or toggles a single bit at a specified position.

 

反转:原来是1,反转后就是0;如果原来是0,toggle后就是1.

不带参数调用,就是反转所有位。

带参数,即是从右边数0开始数,反转第几位。(注意:两点 1是从右边数,2是从0开始)

 

// bitset_flip.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
    using namespace std;
    bitset<5> b1 ( 6 );

    cout << "The collection of bits in the original bitset is: ( "
        << b1 << " )" << endl;

    bitset<5> fb1;
    fb1 = b1.flip ( );

    cout << "After flipping all the bits, the bitset becomes: ( "
        << fb1 << " )" << endl;

    bitset<5> f3b1;
    f3b1 = b1.flip ( 0 );

    cout << "After flipping the fourth bit, the bitset becomes: ( "
        << f3b1 << " )" << endl << endl;

    bitset<5> b2;
    int i;
    for ( i = 0 ; i <= 4 ; i++ )
    {
        b2.flip(i);
        cout << b2 << "  The bit flipped is in position "
            << i << ".\n";
    }
}

 

运行结果:

flip

posted on 2007-07-11 14:12 AlanTop 阅读(730) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理