如何进行移位运算

解决方案 »

  1.   

    int a=0x12345678;
    a=a>>4;//向右移动四位
    a=a<<4;//向左移动四位
      

  2.   

    运算符: >>  <<
    int a=0x01;
    a=a<<2;//a==4
    a=a>>1;//a==2
      

  3.   

    给你看看MSDN中的例子
    Example
    // expre_Shift_Operators.cpp
    // compile with: /EHsc
    // Demonstrate shift operators
    #include <iostream>
    using namespace std;void main() {
       cout   << "5 times 2 is " << (5 << 1) << endl
             << "20 divided by 4 is " << (20 >> 2) << endl;
    }以后在问的时候最好先自己找找!
      

  4.   

    例如:
    int a=1;
    a<<2;左移2位
    a>>3;右移动3位