In Java XOR with three true inputs returns true. Why?

前端 未结 7 1000
一个人的身影
一个人的身影 2021-02-08 00:42

The following code

System.out.println(\"1 0 0: \" + (true ^ false ^ false));
System.out.println(\"1 0 1: \" + (true ^ false ^ true));
System.out.println(\"1 1 0:         


        
7条回答
  •  醉话见心
    2021-02-08 01:30

    true ^ true ^ true can be written (for understanding) as ( true ^ true ) ^ true which is true.

    If A, B, C are inputs, for the logic that you are looking for, you need something like this

    (A & !B & !C) | (!A & B & !C) | (!A & !B & C)
    

提交回复
热议问题