Difference between revisions of "Lua:bNot"

From Cheat Engine
Jump to navigation Jump to search
m (Added CodeBox Template.)
m (Advanced Examples)
 
(One intermediate revision by the same user not shown)
Line 38: Line 38:
 
'''Simple bitwise NOT:'''
 
'''Simple bitwise NOT:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
print( bNot(0x0F) )  -- 0xF0 (in 8-bit context)
 
print( bNot(0x0F) )  -- 0xF0 (in 8-bit context)
</pre>
+
</syntaxhighlight>
  
 
'''Using Lua's NOT operator (equivalent):'''
 
'''Using Lua's NOT operator (equivalent):'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
print( ~0x0F )        -- 0xF0 (in 8-bit context)
 
print( ~0x0F )        -- 0xF0 (in 8-bit context)
</pre>
+
</syntaxhighlight>
  
 
'''Clearing specific bits using NOT and AND:'''
 
'''Clearing specific bits using NOT and AND:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local value = 0xFF
 
local value = 0xFF
 
local mask  = 0x0F
 
local mask  = 0x0F
 
local cleared = bAnd(value, bNot(mask))  -- clears lower 4 bits
 
local cleared = bAnd(value, bNot(mask))  -- clears lower 4 bits
 
print(string.format("0x%X", cleared))  -- 0xF0
 
print(string.format("0x%X", cleared))  -- 0xF0
</pre>
+
</syntaxhighlight>
  
 
=== Behavior ===
 
=== Behavior ===
Line 67: Line 67:
 
'''Inverting multiple flags:'''
 
'''Inverting multiple flags:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local flags = 0x0D  -- 1101
 
local flags = 0x0D  -- 1101
 
local inverted = bNot(flags)  -- 0010 (if 4-bit context)
 
local inverted = bNot(flags)  -- 0010 (if 4-bit context)
 
print(string.format("0x%X", inverted))
 
print(string.format("0x%X", inverted))
</pre>
+
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
 
{{BinaryOps}}
 
{{BinaryOps}}

Latest revision as of 19:59, 25 June 2026

<> Lua API Reference

function bNot(int1) : Integer

Performs a bitwise NOT operation on the given integer. This function inverts all bits of the input value, changing 1s to 0s and 0s to 1s. It behaves the same as Lua's bitwise NOT operator (~) in Cheat Engine.

Function Parameters[edit]

Parameter Type Description
int1 integer The value whose bits will be inverted.

Returns[edit]

An integer representing the bitwise NOT of the input.

Description[edit]

Bitwise NOT flips every bit in the input integer. For example, in an 8-bit context, 0x0F (00001111) becomes 0xF0 (11110000).

Binary example (8-bit representation):

00001111   (0x0F)
--------
11110000   (0xF0)

Common uses include:

  • Inverting masks
  • Clearing specific bits using combination with AND
  • Logical bit manipulation

Usage Examples[edit]

Simple bitwise NOT:

1 print( bNot(0x0F) )   -- 0xF0 (in 8-bit context)

Using Lua's NOT operator (equivalent):

1 print( ~0x0F )         -- 0xF0 (in 8-bit context)

Clearing specific bits using NOT and AND:

1 local value = 0xFF
2 local mask  = 0x0F
3 local cleared = bAnd(value, bNot(mask))  -- clears lower 4 bits
4 print(string.format("0x%X", cleared))  -- 0xF0

Behavior[edit]

  • Returns an integer.
  • Only works on numeric values.
  • Equivalent to Lua's bitwise NOT operator (~) in Cheat Engine.
  • Useful for bitmask manipulation and logical inversions.

Advanced Examples[edit]

Inverting multiple flags:

1 local flags = 0x0D   -- 1101
2 local inverted = bNot(flags)  -- 0010 (if 4-bit context)
3 print(string.format("0x%X", inverted))

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Bitwise Related Lua Functions

bOr – Bitwise OR
bXor – Bitwise XOR
bAnd – Bitwise AND
bShl – Bitwise Shift Left
bShr – Bitwise Shift Right
bNot – Bitwise NOT