Xor运算符如何工作

时间:2016-01-04 11:45:12

标签: c++

有人可以解释一下xor运算符在这两种情况下是如何工作的:

UPDATE Derived
Set Derived.IKey = Derived.IKey - 1

FROM    Derived 
        INNER JOIN
        Base
        ON
            Derived.IKey - 1 = Base.IKey
            AND 
            Derived.Number = Base.Number

WHERE   Derived.IKey
IN
      (
              /** Query to get all records which have duplicates in a table but the previous key is not used**/
              SELECT
                Derived.IKey
              FROM
                Derived
              WHERE
                Derived.IKey - 1 NOT IN (SELECT IKey FROM Derived)
              GROUP BY 
                Derived.IKey
              HAVING 
                COUNT(Derived.IKey) > 1
       )

N是立方体的尺寸数。

2 个答案:

答案 0 :(得分:2)

xor是一个带有跟随真值表的按位运算符:

0 ^ 0 == 0
1 ^ 0 == 1
0 ^ 1 == 1
1 ^ 1 == 0

xyx ^ y中的两个数字中的每一位都会发生这种情况。

答案 1 :(得分:0)

  

Exclusive-Or; From Wikipedia, the free encyclopedia

     

Exclusive-Or [XOR] 是一种逻辑运算,仅当两个输入不同时才输出true(一个为真,另一个为假)。

     

示例:
  1 xor 1 = 0
  1 xor 0 = 1
  0 xor 1 = 1
  0 xor 0 = 0
  1110 xor 1001 = 0111(这相当于没有携带的添加)