Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
考虑到a,b是整数,a^b在swift中意味着什么_Swift_Xcode - Fatal编程技术网

考虑到a,b是整数,a^b在swift中意味着什么

考虑到a,b是整数,a^b在swift中意味着什么,swift,xcode,Swift,Xcode,^运算符在swift中做什么?这是一个按位异或运算符,您可以在swift文档的 对于5^6,它基本上执行以下操作: print(5^6) // the output is 3 print(10^6) // the output is 12 XOR表示“异或”。换句话说,“一个或另一个,但不是两个”。在这种情况下,5和6的“4”位都是打开的,因此其中一个位切换为关闭。“1”位和“2”位分别只对5或6启用,因此它们保持启用状态。因此,对于第一个示例二进制0101xor0110是0011。对于第二个

^
运算符在swift中做什么?

这是一个按位异或运算符,您可以在swift文档的

对于
5^6
,它基本上执行以下操作:

print(5^6) // the output is 3
print(10^6) // the output is 12

XOR表示“异或”。换句话说,“一个或另一个,但不是两个”。在这种情况下,5和6的“4”位都是打开的,因此其中一个位切换为关闭。“1”位和“2”位分别只对5或6启用,因此它们保持启用状态。

因此,对于第一个示例二进制
0101
xor
0110
0011
。对于第二个示例,二进制
1010
xor
0110
1100
5 = 0x00000101
6 = 0x00000110
    0x00000011 = 3