What does the ^ operator do to a BOOL?

后端 未结 7 1760
情深已故
情深已故 2021-01-23 04:10

What does this statement mean?

isChecked = isChecked ^ 1;

isChecked is a BOOL.

7条回答
  •  自闭症患者
    2021-01-23 04:49

    It only flips the last bit of BOOL. Not a reliable way to logically negate. If someone is crazy enough to set the a BOOL variable to some number, for example 5. Then doing ^ 1 will only flip the last bit of the value to 4, which is still evaluated to YES.

    If you want to logically negate, use ! operator instead.

提交回复
热议问题