XOR operation derivation, exchanging data

Source: Internet
Author: User
/* * 5 0101 * 9 1010 * * 5 ^ 5 * 0101 * 0101 *-----* 0000 * Draw the first rule: the same number is different or, the result is 0 * * 9 ^ 5 ^ 6 * 1010 * 0101 *----* 1111 * * 1111 * 0110 *----* 1001 * * 9 ^ 6 ^ 5 * 1010 * 0110 *-----* 1100 * * 1100 * 0101 *-----* 1001 * Get a second rule: different Or the order can be exchanged * * 1001 * 0000 *----* 1001 * * 0101 * 0000 *----* 0101 * Get the third rule: any number and 0 XOR, the result is itself *///Law 1, the same number is different or, the result is 0//  Rule 2, XOR order can be exchanged 9 ^ 5 ^ 6 = 9 ^ 6 ^ 5//Law 3, any number and 0 XOR, the result is itself//derivation   a ^ b ^ a = b//According to 2  a ^ b ^ a = a ^ a ^ b//according to 1  a ^ B ^ a = a ^ a ^ b = 0 ^ b//According to 3  a ^ b ^ a = a ^ a ^ b = 0 ^ b = becho Php_eol;function swap ($a, $b) {    $a ^= $b; 
 //  A = (a ^ b);    $b ^= $a;  b  = (a ^ b) ^ B; The result is B = a    $a ^= $b;  A = (a ^ b) ^ (a ^ b ^ b); Two a merges to 0, two B merges to 0, and finally B, and the result is a = B    echo $a. $b; Swap (1, 2);

The above describes the different or operation deduction, Exchange data, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.