bitwisenot: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page bitwisenot to Bitwisenot without leaving a redirect: Converting page title to first-letter uppercase)
m (Text replacement - "source>" to "syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 26: Line 26:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: val = bnot(num)]
[h: val = bnot(num)]
[h: val = bitwisenot(num)]
[h: val = bitwisenot(num)]
</source>
</syntaxhighlight>


|examples=
|examples=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[bnot(1)]
[bnot(1)]
</source>
</syntaxhighlight>
Returns 0.
Returns 0.


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


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: bnot(12]
[r: bnot(12]
</source>
</syntaxhighlight>
Returns -13.
Returns -13.
}}
}}
[[Category:Logical Function]]
[[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.