XOR operation: returns true if two or more values are the same, and returns false if the two values are the same.
0 XOR 0 = 0
0 XOR 1 = 1
1 XOR 0 = 1
1 XOR 1 = 0
In special cases, there is a 2*2 matrix of all 0. If another Matrix and Its XOR, it is itself: Based on 0 XOR 0 = 0, 1 XOR 0 = 1. The other matrix values remain unchanged.
0 0
0 0
In special cases, there is a 2*2 matrix of all 1. If another matrix is opposite to its XOR: This other matrix value is reversed Based on 0 XOR 1 = 1, 1 XOR 1 = 0.
1 1
1 1
We can see that if a matrix is XOR twice, we can get it.
1. If the value is 0, the value remains unchanged.
2. In case 1, the value is reversed, and the result is reversed twice to the original value.
Of course, it can also be based on the exchange rate: a xor B = a XOR (B xor B) = a XOR (all 0 matrix) =
For a graph, if two graphs A and B need to be superimposed, extract an irregular part from the graph B and place it on the graph:
This principle can be based on XOR:
1. Based on the principle of a monochrome graph, use B to generate a masked monochrome graph C. In the mask graph, the truncated part is set to 0. In the other part, set it to 1.
2. Bit operations
Figure A = figure a XOR B
Graph A = Graph A and mask graph C (this operation enables the corresponding part of Graph A to form a full 0 matrix)
Figure A = figure a xor B (all 0 matrix part xor B corresponding to figure a remains unchanged according to the feature of X or all 0 matrix, thus retaining the part intercepted by Figure B, others are not affected, and the original situation of A is directly restored)
The above is the principle of introduction. For the implementation code, refer:
Http://www.cnblogs.com/syxchina/archive/2010/06/01/2197688.html
XOR exclusive or logical operations (helping to overlay images)