很抱歉问这么简单的问题,但这些东西在谷歌上很难找到答案。
我有iOS代码连接到切换器,可以在摄氏度和华氏度之间切换,但我不知道 ^ 1 是什么意思。self.celsius是一个布尔值。
谢谢
self.celsius = self.celsius ^ 1;
很抱歉问这么简单的问题,但这些东西在谷歌上很难找到答案。
我有iOS代码连接到切换器,可以在摄氏度和华氏度之间切换,但我不知道 ^ 1 是什么意思。self.celsius是一个布尔值。
谢谢
self.celsius = self.celsius ^ 1;
0101 (decimal 5)
XOR 0011 (decimal 3)
= 0110 (decimal 6)
0010 (decimal 2)
XOR 1010 (decimal 10)
= 1000 (decimal 8)
0 ^ 1
是1,1 ^ 1
是0。这是一个异或操作。
self.celsius = ! self.celsius
,这只会让人感到困惑,对吧? - Robert