ios_type ^ = 0x1,这是什么意思?

Pet*_*ros 2 c objective-c ios

  - (void)methedName{
      if(){
        _type ^=0x1;
      }
    }
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

rob*_*off 10

你的问题的标题和你的代码做了不同的事情.

0x1表示"1"被解释为十六进制数字.这恰好与十进制中的1相同.

所以_type =0x1简单地设置_type为1.

^ 表示XOR(异或)运算符.

^=表示用右侧计算左侧的XOR,并将结果分配给左侧.换句话说,ios_type ^= 0x1就是一样ios_type = ios_type ^ 0x1.

所以ios_type ^= 0x1切换1位ios_type.