C++ 位运算符

int main(int argc, char* argv[])
{
    unsigned short x=3,y=5;
    cout<<"~x="<<(unsigned short)~x<<endl;//位求反
    cout<<"~x="<<~x<<endl;//位求反
    cout<<"x&y="<<(x&y)<<endl;//位与
    cout<<"x^y="<<(x^y)<<endl;//位异或
    cout<<"x|y="<<(x|y)<<endl;//位或
    cout<<"x<<1="<<(x<<1)<<endl;//位左移
    cout<<"y>>1="<<(y>>1)<<endl;//位右移
    return 0;
}

 

posted @ 2013-05-12 22:27  Leung文  阅读(179)  评论(0编辑  收藏  举报