xor

x xor y

xor(x, y)

Try it yourself:

See also:

Test exclusive alternatives with xor

xor(a, b) returns true when exactly one of its Boolean inputs is true. It returns false when both inputs agree: both true or both false. Exclusive OR is useful for validations where one—and only one—option must be selected.

Reading an xor condition

For example, a form may allow either a delivery address or a pickup location, but not both. Xor expresses that rule directly. Compare or, which allows one or both conditions, and and, which requires both. Use not to invert a condition before combining it.

Logical and bitwise use

This function is for logical conditions. For integer bit patterns, use bitXor, which applies the same exclusive-or idea to each binary digit. Keep these operations separate: a truth test is not automatically a request to manipulate integer bits.

Input caveats

Make Boolean intent explicit, particularly when input values may be empty strings, zero, or missing. Parenthesize compound expressions so the intended evaluation order is clear. If the requirement is “values differ” rather than “exactly one condition holds,” unequal may better describe the comparison.

Try Xor in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions