^在客观c中意味着什么? [英] What does ^ mean in objective c ios?

查看:118
本文介绍了^在客观c中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉提出这么简单的问题,但这些事情对谷歌来说很难。

Sorry to ask such a simple question but these things are hard to Google.

我在iOS中有代码连接到在Celsius和Fahrenheit之间切换的切换我不知道^ 1的意思。 self.celsius是布尔值

I have code in iOS which is connected to toggle which is switching between Celsius and Fahrenheit and I don't know what ^ 1 means. self.celsius is Boolean

谢谢

self.celsius = self.celsius ^ 1;


推荐答案

这是一个C语言运算符,意思是按位异或 。

It's a C-language operator meaning "Bitwise Exclusive OR".

维基百科给出了一个很好的解释:

Wikipedia gives a good explanation:

XOR


按位异或需要两位等长的模式,并对每对相应的位执行
逻辑异或运算。如果只有第一位为1或只有
秒位为1,则每个位置的
结果为1,但如果两者均为0或两者均为1,则为0.在此我们
执行两位的比较,如果两位是
不同则为1,如果它们相同则为0。例如:

A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. In this we perform the comparison of two bits, being 1 if the two bits are different, and 0 if they are the same. For example:



    0101 (decimal 5)
XOR 0011 (decimal 3)
  = 0110 (decimal 6)




按位异或可能用于反转寄存器
中的选定位(也称为切换或翻转)。任何位都可以通过与
1进行异或来切换。例如,给定位模式0010(十进制2),第二和第四位可以通过按位XOR切换,其中位模式
包含1 in第二和第四个职位:

The bitwise XOR may be used to invert selected bits in a register (also called toggle or flip). Any bit may be toggled by XORing it with 1. For example, given the bit pattern 0010 (decimal 2) the second and fourth bits may be toggled by a bitwise XOR with a bit pattern containing 1 in the second and fourth positions:



    0010 (decimal 2)
XOR 1010 (decimal 10)
  = 1000 (decimal 8)

这篇关于^在客观c中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆