The xor Command


Command Summary

Tests if exactly one of two conditions is true.
Can also be used as a bitwise "xor" on integers.

Command Syntax

condition1 xor condition2
integer1 xor integer2

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press 8 to enter the Test submenu.
  • Press A to select xor.

Calculator Compatibility

This command works on all calculators.

Token Size

1 byte

The "xor" (eXclusive OR) operator combines two conditions into one, which will be true if exactly one side is true, and false otherwise. You can create these conditions with the relational operators =, , >, , <, and , with functions such as isPrime(), pxlTest(), and ptTest(), or with any other expression that returns 'true' or 'false'. Other operators for dealing with conditions are and, or, and not.

:2+2=4 xor 1=0
:2+2=4 xor 1+1=2

The operator can also be applied to integers, treating them as 32-bit signed integers (larger integers will be truncated to fit) expressed in binary. The bits will be matched up, and "xor" will be applied to the bits individually — a bit in the result will be 1 if the two corresponding bits of the original integers were different, and 0 if they were the same.

:(0b11111100 xor 0b00111111)▶Bin
:1000 xor 512

In complicated logical expressions (both with conditions and with integers), "and" has greater priority than the others ("or" and "xor"). For instance, X or Y and Z will be interpreted as X or (Y and Z).

Error Conditions

60 - Argument must be a Boolean expression or integer happens when the data type is incorrect (or mismatched).

Related Commands

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.