bitwiseand: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page Bitwiseand to bitwiseand: Converting page titles to lowercase) |
m (Text replacement - "source>" to "syntaxhighlight>") |
||
Line 18: | Line 18: | ||
[h: val = band(num, num, ...)] | [h: val = band(num, num, ...)] | ||
[h: val = bitwiseand(num, num, ...)] | [h: val = bitwiseand(num, num, ...)] | ||
</ | </syntaxhighlight> | ||
|examples= | |examples= | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[r: band(1,0)] | [r: band(1,0)] | ||
</ | </syntaxhighlight> | ||
Returns 0. | Returns 0. | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[r: band(1,1)] | [r: band(1,1)] | ||
</ | </syntaxhighlight> | ||
Returns 1. | Returns 1. | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[r: band(3, 5] | [r: band(3, 5] | ||
</ | </syntaxhighlight> | ||
Returns 1. | Returns 1. | ||
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. | 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. | ||
Line 39: | Line 39: | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[r: band(20, 12)] | [r: band(20, 12)] | ||
</ | </syntaxhighlight> | ||
Returns 4. | 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. | 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. | ||
}} | }} | ||
[[Category:Logical Function]] | [[Category:Logical Function]] |
Revision as of 17:04, 14 March 2023
bitwiseand() Function
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.
Logical "and" Table
Bit1 | Bit2 | Result |
0 | 0 | 0 |
0 | 1 | 0 |
1 | 1 | 1 |
Usage
<source lang="mtmacro" line> [h: val = band(num, num, ...)] [h: val = bitwiseand(num, num, ...)] </syntaxhighlight>
Examples
<source lang="mtmacro" line>
[r: band(1,0)] </syntaxhighlight> Returns 0.
<source lang="mtmacro" line> [r: band(1,1)] </syntaxhighlight> Returns 1.
<source lang="mtmacro" line> [r: band(3, 5] </syntaxhighlight> Returns 1. 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: band(20, 12)] </syntaxhighlight> 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.