mirror of
https://github.com/QB64Official/qb64.git
synced 2024-09-01 18:40:17 +00:00
50 lines
No EOL
2.1 KiB
Text
50 lines
No EOL
2.1 KiB
Text
The '''XOR''' numerical operator returns the bitwise exclusive [[OR]] value where only bits that differ return a bit value.
|
|
|
|
|
|
{{PageSyntax}}
|
|
::: result% = ''value1%'' [[XOR]] ''value2%''
|
|
|
|
|
|
* Given two [[INTEGER|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.
|
|
|
|
|
|
{{Template:LogicalTruthTable}}
|
|
|
|
|
|
''Example 1:'' Comparing the results of XOR, AND and OR value comparisons on one byte number values up to 255.
|
|
{{WhiteStart}}
|
|
|
|
' 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
|
|
|
|
{{WhiteEnd}}
|
|
:''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
|
|
{{CodeStart}}
|
|
address% = 888
|
|
ByteValue% = {{Cl|INP}}(address%)
|
|
{{Cl|OUT}} address%, ByteValue% {{Cl|XOR}} 7
|
|
{{CodeEnd}}
|
|
:''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.
|
|
|
|
|
|
''See also:''
|
|
* [[AND]], [[OR]] {{text|(logical operators)}}
|
|
* [[Binary]], [[Boolean]]
|
|
|
|
|
|
{{PageNavigation}} |