Optimize the if condition

  • A+
Category:Languages

I want to simplify this condition where a and b are booleans

!((a && b) || (!a && !b)) 

I have tried using the truth table generator, but I am not able to figure out the simplified version.


This can be simplified as a XOR (exclusive or). It's equivalent to (a && !b) || (!a && b).

In Java, it can be achieved as a ^ b

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: