Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XOR Objective-c

Tags:

Is there a way to put a condition that return true only if one of the two component return true?

BOOL var1 BOOL var2 

something shorter than if((var1 && !var2) || (!var1 && var2))

Thank you

like image 971
Nicolas Manzini Avatar asked Jul 11 '12 11:07

Nicolas Manzini


People also ask

What is XOR condition?

XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).

What is meant by XOR operation?

(eXclusive OR) A Boolean logic operation that is widely used in cryptography as well as in generating parity bits for error checking and fault tolerance. XOR compares two input bits and generates one output bit. The logic is simple. If the bits are the same, the result is 0. If the bits are different, the result is 1.

Why does Objective C use yes and no?

It's just syntax, there's no technical reason for it. They just use YES/NO for their BOOL instead of true/false like c++ does.


1 Answers

As Objective-C is a superset of C, you simply use the XOR operator from C, which is ^.

like image 178
Cyrille Avatar answered Sep 22 '22 14:09

Cyrille