XOR (GO) in Java

Source: Internet
Author: User


    
Xor in Java program:  

Same output 0, different output 1, for example:  
System.out.println (1^1); output 0  
System.out.println (1^2); output 3, because the last 2 lows are not the same, all outputs 3 

    The concept of the exotic is the same as 0 different for 1. If two values are the same, they may be different before or after.  
such as binary: 0010^0001=0011 and 0000^0011=0011. To be used with caution.  


    to interesting topics: Many paired occurrences of numbers are saved in a disk file, noting that the paired numbers are not necessarily contiguous, such as 2, 3, 4, 3, 4, 2 ..., because an unexpected number disappears, How quickly to find out which number is missing?  

   because a number disappears, there must be a number that appears once and the other numbers appear even several times. It is not necessary to use the search to do it, using the two characteristics of the XOR operation--1. Oneself or the result is 0,2. xor or satisfying   the
commutative law. &NBSP

public static int findlost (int a[]) { 
        int result=0; &NBSP
        for (int i=0;i<a.length;i++) { 
             result^=a[i]; 
        } 
        return result; 


Order disruption is also not related.

Transferred from: http://longcxm.iteye.com/blog/1461543

XOR (GO) in Java

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.