bitwisexor: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function bxor== Performs a bitwise 'exlusive or' operation of the number arguments by taking the binary representation of each of the numbers and performing the logical exclusive or oper...)
 
m (Text replacement - "<source" to "<syntaxhighlight")
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function bxor==
{{MacroFunction
Performs a bitwise 'exlusive or' operation of the number arguments by taking the binary representation of each of the numbers and performing the logical exclusive or operation on each of the bits.
|name=bitwisexor
|description=Performs a bitwise 'exlusive or' operation of the number arguments by taking the binary representation of each of the numbers and performing the logical exclusive or operation on each of the bits.


'''Logical " exclusive or" Table'''
'''Logical " exclusive or" Table'''
{|
{{{!}}
|Bit1 || Bit2 || Result
{{!}}Bit1 {{!}}{{!}} Bit2 {{!}}{{!}} Result
|-
{{!}}-
|align=center| 0 || align=center| 0 || align=center| 0
{{!}}align=center{{!}} 0 {{!}}{{!}} align=center{{!}} 0 {{!}}{{!}} align=center{{!}} 0
|-
{{!}}-
|align=center| 0 || align=center| 1 || align=center| 1
{{!}}align=center{{!}} 0 {{!}}{{!}} align=center{{!}} 1 {{!}}{{!}} align=center{{!}} 1
|-
{{!}}-
|align=center| 1 || align=center| 1 || align=center| 0
{{!}}align=center{{!}} 1 {{!}}{{!}} align=center{{!}} 1 {{!}}{{!}} align=center{{!}} 0
|}
{{!}}}


 
|usage=
===Usage===
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[h: val = bxor(num, num, ...)]
[h: val = bxor(num, num, ...)]
[h: val = bitwisexor(num, num, ...)]
[h: val = bitwisexor(num, num, ...)]
</source>
</syntaxhighlight>


===Examples===
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: bor(1,0)]
[r: bxor(1,0)]
</source>
</syntaxhighlight>
Returns 1.
Returns 1.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: bor(1,1)]
[r: bxor(1,1)]
</source>
</syntaxhighlight>
Returns 0.
Returns 0.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: bor(0,0)]
[r: bxor(0,0)]
</source>
</syntaxhighlight>
Returns 0.
Returns 0.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: bor(2, 4]
[r: bxor(2, 4]
</source>
</syntaxhighlight>
Returns 6.
Returns 6.
2 in binary is 010 and 4 in binary is 100, so a bitwise or of these two values is 110 which is 6 in decimal.
2 in binary is 010 and 4 in binary is 100, so a bitwise xor of these two values is 110 which is 6 in decimal.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: band(6, 4)]
[r: bxor(6, 4)]
</source>
</syntaxhighlight>
Returns 2.       
Returns 2.       
6 in binary is 110 and 4 in binary is 100, so a bitwise or of these two values is 010 which is 2 in decimal.
6 in binary is 110 and 4 in binary is 100, so a bitwise xor of these two values is 010 which is 2 in decimal.
}}
[[Category:Logical Function]]

Latest revision as of 18:00, 14 March 2023

bitwisexor() Function

Performs a bitwise 'exlusive or' operation of the number arguments by taking the binary representation of each of the numbers and performing the logical exclusive or operation on each of the bits.

Logical " exclusive or" Table

Bit1 Bit2 Result
0 0 0
0 1 1
1 1 0

Usage

[h: val = bxor(num, num, ...)]
[h: val = bitwisexor(num, num, ...)]

Examples

[r: bxor(1,0)]

Returns 1.

[r: bxor(1,1)]

Returns 0.

[r: bxor(0,0)]

Returns 0.

[r: bxor(2, 4]

Returns 6. 2 in binary is 010 and 4 in binary is 100, so a bitwise xor of these two values is 110 which is 6 in decimal.

[r: bxor(6, 4)]

Returns 2.

6 in binary is 110 and 4 in binary is 100, so a bitwise xor of these two values is 010 which is 2 in decimal.