Futurebasic/Language/Reference/xor
Appearance
(Redirected from Futurebasic/language/reference/xor)
XOR
[edit | edit source]Syntax
[edit | edit source]result& = exprA {XOR | ^^} exprB
Description
[edit | edit source]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 position in exprB
. The result is another 32-bit quantity; each bit in the result is determined as follows:
<image was here>
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
[edit | edit source]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: <code>00000000000000000000001110011011 00000000000000000000000001111011 -------------------------------- 00000000000000000000001111100000