bitwiseor: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function band== Performs a bitwise 'and' operation of the {number} arguments by taking the binary representation of each of the numbers and performing the logical and operation on each o...)
 
No edit summary
Line 1: Line 1:
==Function band==
==Function bor==
Performs a bitwise 'and' operation of the {number} arguments by taking the binary representation of each of the numbers and performing the logical and operation on each of the bits.
Performs a bitwise 'or' operation of the number arguments by taking the binary representation of each of the numbers and performing the logical or operation on each of the bits.


'''Logical "and" Table'''
'''Logical "or" Table'''
{|
{|
|Bit1 || Bit2 ||  Result
|Bit1 || Bit2 ||  Result
Line 8: Line 8:
|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| 0
|align=center| 0 || align=center| 1 || align=center| 1
|-
|-
|align=center| 1 || align=center| 1 || align=center| 1
|align=center| 1 || align=center| 1 || align=center| 1
Line 16: Line 16:
===Usage===
===Usage===
<source lang="mtmacro" line>
<source lang="mtmacro" line>
[h: val = band(num, num, ...)]
[h: val = bor(num, num, ...)]
[h: val = btwiseand(num, num, ...)]
[h: val = btwiseor(num, num, ...)]
</source>
</source>


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


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


<source lang="mtmacro" line>
<source lang="mtmacro" line>
[r: band(3, 5]
[r: bor(0,0)]
</source>
</source>
Returns 1.
Returns 0.
3 in binary is 011 and 5 in binary is 101, the bitwise 'and' of these values is 001 in binary which is 1 in decimal.
 
<source lang="mtmacro" line>
[r: bor(2, 4]
</source>
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.
 
 


<source lang="mtmacro" line>
<source lang="mtmacro" line>

Revision as of 13:02, 1 December 2008

Function bor

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

Logical "or" Table

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


Usage

[h: val = bor(num, num, ...)]
[h: val = btwiseor(num, num, ...)]

Examples

[r: bor(1,0)]

Returns 1.

[r: bor(1,1)]

Returns 1.

[r: bor(0,0)]

Returns 0.

[r: bor(2, 4]

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.


[r: band(20, 12)]

Returns 4. 20 in binary is 10100 and 12 in binary is 01100, the bitwise 'and' of these values is 00100 in binary which is 4 in decimal.