午夜稻草人

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include <iostream>
using namespace std;

const int STATUS_SIZE = 30;

int main()
{
    int status = 0;

    //set status : set the fifth position is true
    status = status | 1 << 4;
    cout << status << endl;

    //test if the fifth position is true
    if (status >> 4 & 1)
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    //test if all the position is true
    if (status == (1 << STATUS_SIZE - 1))
        cout << "yes" << endl;
    else
        cout << "no" << endl;

    
    status = status | 1 << 2;
    cout << status << endl;

    //unset status : set the fifth position is false
    status = status & ~(1 << 4);
    cout << status << endl;



}

 

posted on 2015-07-22 17:19  午夜稻草人  阅读(256)  评论(0编辑  收藏  举报