C Programming - XOR Bitwise Operation

后端 未结 6 1145
傲寒
傲寒 2020-12-07 06:01

What operation does the following ‘C’ statement perform?

star = star ^ 0b00100100;

(A) Toggles bits 2 and 5 of

6条回答
  •  感情败类
    2020-12-07 06:29

    The exclusive OR has this truth table:

    A   B   A^B
    -----------
    1   1   0
    1   0   1
    0   1   1
    0   0   0
    

    We can see that if B is true (1) then A is flipped (toggled), and if it's false (0) A is left alone. So the answer is (A).

提交回复
热议问题