From QB64 Wiki
The XOR numerical operator returns the bitwise exclusive OR value where only bits that differ return a bit value.
- result% = value1% XOR value2%
- Given two whole integer type values XOR returns an integer with the property that each bit returns:
- a bit value of 0 if both of the corresponding bit values compared are off or on.
- a bit value of 1 if one of the two compared bit values is on and the other is off.
- XOR can be used to turn off bits that are on or turn on bits that are off, like toggling the bit values.
- Byte (8 bit) values can be from 0 to 255. 0 = all bits off. 255 = all bits on.
Operands Operations A B NOT B A AND B A OR B A XOR B A EQV B A IMP B T T F T T F T T T F T F T T F F F T F F T T F T F F T F F F T T
Example 1: Comparing the results of XOR, AND and OR value comparisons on one byte number values up to 255.
' bit# 76543210 also the exponent of 2 value on ' -------- a% = 233 ' binary 11101001 values used b% = 111 ' binary 01101111 ' -------- result1% = a% XOR b% ' 10000110 binary Result1% = 134 result2% = a% AND b% ' 01101001 binary Result2% = 105 result3% = a% OR b% ' 11101111 binary Result3% = 239
- Explanation: Look down the columns to see how the bits are changed. The three values returned by XOR, AND and OR are relational. If you add the values returned by XOR(134) and AND(105) the result is the value of the OR operation, 239.
Example 2: Using XOR to turn a parallel port's data register bits on or off
- Explanation: Only the first 3 Bits are affected. If on then turned off. If off then turned on. Each time the OUT statement above is used, the bit values alternate. That is because the value of 7 compares the bit's status to an on only value.