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