Exclusive OR (xor) is a mathematical operator. It is used in logical operations. The computer notation is "xor". The algorithm is:
a⊕b = (¬a ∧ b) ∨ (a ∧¬b)
If the values a and b are not the same, the XOR result is 1 . If the values of a and b are the same, the XOR result is 0.
XOR is also called half addition operation. Its operation rule is equivalent to binary addition without carry: in binary, 1 represents true and 0 represents false. The operation rule of XOR is: 0⊕0= 0, 1⊕0=1, 0⊕1=1, 1⊕1=0 (the same is 0, the difference is 1), these rules are the same as addition, but without carry, so XOR is often regarded as Add without carry.
##a ⊕ a = 0 a ⊕ b = b ⊕ a a ⊕b ⊕ c = a ⊕ (b ⊕ c) = (a ⊕ b) ⊕ c d = a ⊕ b ⊕ c It can be deduced that a = d ⊕ b ⊕ c a ⊕ b ⊕ a = b If x is a binary number 0101 and y is a binary number 1011; then x⊕y=1110 True⊕False=True False⊕True=True False⊕ False = False True⊕True=False Related recommendations: "Python Video Tutorial"
XOR Operator
The XOR of C language and C language is to use "^" to perform the "XOR" operation on two data participating in the operation based on binary bits. Operation rules: 0^0=0; 0^1=1; 1^0=1; 1^1=0; That is: two objects participating in the operation, if two If the corresponding bit is "exclusive" (the value is different), the result of the bit is 1, otherwise it is 0.The special function of "XOR operation":
(1) Flip specific bits to find a number that corresponds to the bits of X to be flipped. The corresponding bit is 1, and the remaining bits are zero. This number can be XORed with the corresponding bit of X. Example: X=10101110, flip the lower 4 bits of (2) XOR with 0, retain the original value, X ^ 00000000 = 1010 1110.The above is the detailed content of What does xor mean in python. For more information, please follow other related articles on the PHP Chinese website!