FutureBasic Logo

<<    Index    >> FutureBasic 5

xor   operator



Syntax:
result = exprA {xor | ^^} exprB

Description:
Expression exprA and expression exprB are each interpreted as 32-bit integer quantities. The xor operator performs a "bitwise comparison" of each bit in exprA with the bit in the corresponding posistion in exprB. The result is another 32-bit quantity; each bit in the result is determined as follows:

Bit value in
expr
Bit value in
expr
Bit value in
result
000
101
011
110

A common use for xor is to toggle the state of individual bits in a bit pattern. For example:
   pattern = pattern xor bit(7)

This flips bit 7 in pattern from 0 to 1 or from 1 to 0, and leaves all of pattern's  other bits alone.

Example:
The example below shows how bits are manipulated with xor:
defstr long
print bin$(923)
print bin$(123)
print "--------------------------------"
print bin$(923 xor 123)

program output:
00000000000000000000001110011011
00000000000000000000000001111011
--------------------------------
00000000000000000000001111100000


See Also:
and; or; not