XOR exclusive or logical operations (helping to overlay images)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.