C按位运算

时间:2013-02-04 04:53:24

标签: c

  

可能重复:
  Bitwise Operation and Usage

是输入。需要放0,1,x或x̅:

    x & 0 = 0

    x & 1 = x

    x | 0 = x
    x | 1 = 0
    x ^ 0 = 1
    x ^ 1 = 

2 个答案:

答案 0 :(得分:1)

如果x是布尔值,那么!x是x的布尔否定。这是你的'翻转'。

要开启和关闭,只需执行x = 1x = 0

答案 1 :(得分:1)

x & 0 = 0

x & 1 = x

x | 0 = x
x | 1 = 1
x ^ 0 = x
x ^ 1 = 0 if x is 1, 1 if x is 0