异或排序
2017-07-25 本文已影响0人
李一L
int a =95;
int b = 59;
a = a^b;
NSLog(@"%d",a); //a 为一个非 a 非 b 数
b = a^b;
//NSLog(@"%d",a);
NSLog(@"%d",b);// b 为 a b = a^b^b a^b = a 所以b =a;
a = a^b; a = a^a^b
NSLog(@"%d",a);
int a =95;
int b = 59;
a = a^b;
NSLog(@"%d",a); //a 为一个非 a 非 b 数
b = a^b;
//NSLog(@"%d",a);
NSLog(@"%d",b);// b 为 a b = a^b^b a^b = a 所以b =a;
a = a^b; a = a^a^b
NSLog(@"%d",a);