股票数据格式 外汇交易系统 MT4编程 电子海图开发(S52 S57) AIS

http://alantop.5166.info

股票数据格式 外汇交易系统 MT4编程 电子海图开发(S52 S57) AIS
随笔 - 233, 文章 - 1, 评论 - 383, 引用 - 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 阅读(202) 评论(0)  编辑 收藏 引用 所属分类: C++


标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]




股票数据格式 外汇交易系统 MT4编程 电子海图开发(S52 S57) AIS