int a,b; 
a^b是什么意思?其中的^是什么运算操作符?没看到过。

解决方案 »

  1.   

    Bitwise Exclusive OR Operator: ^ 
    The bitwise exclusive OR operator (^) compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.Both operands to the bitwise exclusive OR operator must be of integral types. The usual arithmetic conversions covered in Arithmetic Conversions are applied to the operands.Operator Keyword for ^
    The xor operator is the text // expre_Bitwise_Exclusive_OR_Operator.cpp
    // compile with: /EHsc
    // Demonstrate bitwise exclusive OR
    #include <iostream>
    using namespace std;
    int main() {
       unsigned short a = 0x5555;      // pattern 0101 ...
       unsigned short b = 0xFFFF;      // pattern 1111 ...   cout  << hex << ( a ^ b ) << endl;   // prints "aaaa" pattern 1010 ...
    }
      

  2.   

    // expre_Bitwise_Exclusive_OR_Operator.cpp 
    // compile with: /EHsc 
    // Demonstrate bitwise exclusive OR 
    #include <iostream> 
    using namespace std; 
    int main() { 
      unsigned short a = 0x5555;      // pattern 0101 ... 
      unsigned short b = 0xFFFF;      // pattern 1111 ...   cout  < < hex < < ( a ^ b ) < < endl;  // prints "aaaa" pattern 1010 ... 

      

  3.   

    2
    如:
    a += b; <=> a = a+b;
    我想
    a ^= b; <=> a = a^b;
      

  4.   

    按位异或吧。就是转换为二进制后进行异或的运算。只要区别它与逻辑异或区别就行了。
    a ^= b 相当于 a = a^b