bitwisenot: 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...)
 
m (Text replacement - "source>" to "syntaxhighlight>")
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function band==
{{MacroFunction
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.
|name=bitwisenot
|description=Performs a bitwise 'not' operation of the {number}. A bitwise not is performed by taking the binary representation of the {number} and performing a logical 'not' operation on each of these bits.


'''Logical "and" Table'''
'''Logical "not" Table'''
{|
{{{!}}
|Bit1 || Bit2 || Result
{{!}}Bit {{!}}{{!}} Result
|-
{{!}}-
|align=center| 0 || align=center| 0 || align=center| 0
{{!}}align=center{{!}} 0 {{!}}{{!}} align=center{{!}} 1
|-
{{!}}-
|align=center| 0 || align=center| 1 || align=center| 0
{{!}}align=center{{!}} 1 {{!}}{{!}} align=center{{!}} 0
|-
{{!}}}
|align=center| 1 || align=center| 1 || align=center| 1
|}


   
Unfortunately its not quite as simple as the table above makes it appear since number are a string of 32 (or more bits) so a 1 in binary is actually a 00000000000000000000000000000001 and a 0 is actually a 00000000000000000000000000000000 so the table is now.


===Usage===
        bnot of binary 00000000000000000000000000000000
<source lang="mtmacro" line>
                is            11111111111111111111111111111111
[h: val = band(num, num, ...)]
        which is -1 in decimal
[h: val = btwiseand(num, num, ...)]
</source>


===Examples===
        bnot of binary 00000000000000000000000000000001
<source lang="mtmacro" line>
        is            11111111111111111111111111111110
[band(1,0)]
        which is -2 in decimal
</source>
 
If you are unsure why the results are negative then you can get more information by reading [[wp:Twos_complement|Twos_complement]]
 
|usage=
<syntaxhighlight lang="mtmacro" line>
[h: val = bnot(num)]
[h: val = bitwisenot(num)]
</syntaxhighlight>
 
|examples=
<syntaxhighlight lang="mtmacro" line>
[bnot(1)]
</syntaxhighlight>
Returns 0.
Returns 0.


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: band(1,1)]
[r: bnot(1)]
</source>
</syntaxhighlight>
Returns 1.
Returns 0.
 
<source lang="mtmacro" line>
[r: band(3, 5]
</source>
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>
<syntaxhighlight lang="mtmacro" line>
[r: band(20, 12)]
[r: bnot(12]
</source>
</syntaxhighlight>
Returns 4.    
Returns -13.
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]]

Latest revision as of 18:39, 14 March 2023

bitwisenot() Function

Performs a bitwise 'not' operation of the {number}. A bitwise not is performed by taking the binary representation of the {number} and performing a logical 'not' operation on each of these bits.

Logical "not" Table

Bit Result
0 1
1 0


Unfortunately its not quite as simple as the table above makes it appear since number are a string of 32 (or more bits) so a 1 in binary is actually a 00000000000000000000000000000001 and a 0 is actually a 00000000000000000000000000000000 so the table is now.

       bnot of binary 00000000000000000000000000000000
               is             11111111111111111111111111111111
       which is -1 in decimal
       bnot of binary 00000000000000000000000000000001 
       is             11111111111111111111111111111110
       which is -2 in decimal
If you are unsure why the results are negative then you can get more information by reading Twos_complement

Usage

[h: val = bnot(num)]
[h: val = bitwisenot(num)]

Examples

[bnot(1)]

Returns 0.

[r: bnot(1)]

Returns 0.

[r: bnot(12]
Returns -13.