What does xor mean in python

爱喝马黛茶的安东尼
Release: 2019-06-26 14:22:20
Original
11409 people have browsed it

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.

What does xor mean in python

##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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!