Binary XOR Operation

The binary XOR (exclusive OR) operation has two inputs and one output. It is like the ADD operation which takes two arguments (two inputs) and produces one result (one output).

The inputs to a binary XOR operation can only be 0 or 1 and the result can only be 0 or 1

The binary XOR operation (also known as the binary XOR function) will always produce a 1 output if either of its inputs is 1 and will produce a 0 output if both of its inputs are 0 or 1.

If we call the inputs A and B and the output C we can show the XOR function as:

0 XOR 0->0
0 XOR 1->1
1 XOR 0->1
1 XOR 1->0

The PIC machine code XOR instruction operates on 8 sets of inputs and outputs in parallel.

If we XOR two input bytes together on the PIC we get an output byte. If we give each bit within a byte a number we can see that each bit in the output is the result of the XOR function on two corresponds bits of the input


  A7 A6 A5 A4 A3 A2 A1 A0
  B7 B6 B5 B4 B3 B2 B1 B0
  C7 C6 C5 C4 C3 C2 C1 C0
So if we have two binary numbers 00100100 and 00100001 we can see the effect of XORing these two sets of 8 bits in parallel.
argument 1 0 0 1 0 0 1 0 0
argument 2 0 0 1 0 0 0 0 1
result 0 0 0 0 0 1 0 1

The input bits A5 and B5 and the output bit C5 are here shown in red

The input bits A2 and B2 and the output bit C2 are here shown in green

The input bits A1 and B1 and the output bit C1 are here shown in yellow

The input bits A0 and B0 and the output bit C0 are here shown in blue

In XCSB the binary XOR operator works in the same way, operating in parallel on sets of inputs and outputs within a variable or constant.

If we assign the value 0x24 to the variable J, which is the hexadecimal equivalent of the binary value 00100100, the value 0x21 to the variable K which is the hexadecimal equivalent of the binary value 00100001 and then perform the XCSB XOR operation on J and K and assign the result to M. The value stored in M will be 0x05 which is the hexadecimal equivalent of the binary value 00000101

Written as XCSB source code this would be:

	J = 0x24
	K = 0x21
	M = J ^ K