规则,相同则为假,不同则为真1 ^ 1 = 01 ^ 0 = 1 以下为测试脚本。例子1是判断一个数组所有的元素是否一致,例子2是异或做简单加密的方法。void OnEnable(){ Example1(); Example2();}void Example1(){ v ...
规则,相同则为假,不同则为真
1 ^ 1 = 0
1 ^ 0 = 1
以下为测试脚本。例子1是判断一个数组所有的元素是否一致,例子2是异或做简单加密的方法。
void OnEnable(){ Example1(); Example2();}void Example1(){ var a = new int[] { 6, 6, 6, 6, 6, 6 }; var b = a[0]; for (int i = 0; i < a.Length; i++) { b = a[i] ^ b; } Debug.Log(b == 0);//true}void Example2(){ var a = 4; var key = 3; var b = a; b = b ^ key; //encryption. Debug.Log((b ^ key) == a);//true //check.}
原标题:^异或运算及其应用
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。