Difference between revisions of "Lua:bNot"
Jump to navigation
Jump to search
(Major overhaul of the post.) |
|||
| Line 1: | Line 1: | ||
| − | + | [[Category:Lua]] | |
| + | '''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 (<code>~</code>) in Cheat Engine. | ||
| + | |||
| + | === Function Parameters === | ||
| + | {|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;" align="left"|Description | ||
| + | |- | ||
| + | |int1 | ||
| + | |integer | ||
| + | |The value whose bits will be inverted. | ||
| + | |} | ||
| + | |||
| + | === Returns === | ||
| + | An integer representing the bitwise NOT of the input. | ||
| + | |||
| + | === Description === | ||
| + | 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):''' | ||
| + | |||
<pre> | <pre> | ||
| − | + | 00001111 (0x0F) | |
| − | + | -------- | |
| − | + | 11110000 (0xF0) | |
| − | |||
| − | |||
| − | ----- | ||
| − | |||
</pre> | </pre> | ||
| + | |||
| + | Common uses include: | ||
| + | |||
| + | * Inverting masks | ||
| + | * Clearing specific bits using combination with AND | ||
| + | * Logical bit manipulation | ||
| + | |||
| + | === Usage Examples === | ||
| + | '''Simple bitwise NOT:''' | ||
| + | |||
| + | <pre> | ||
| + | print( bNot(0x0F) ) -- 0xF0 (in 8-bit context) | ||
| + | </pre> | ||
| + | |||
| + | '''Using Lua's NOT operator (equivalent):''' | ||
| + | |||
| + | <pre> | ||
| + | print( ~0x0F ) -- 0xF0 (in 8-bit context) | ||
| + | </pre> | ||
| + | |||
| + | '''Clearing specific bits using NOT and AND:''' | ||
| + | |||
| + | <pre> | ||
| + | local value = 0xFF | ||
| + | local mask = 0x0F | ||
| + | local cleared = bAnd(value, bNot(mask)) -- clears lower 4 bits | ||
| + | print(string.format("0x%X", cleared)) -- 0xF0 | ||
| + | </pre> | ||
| + | |||
| + | === Behavior === | ||
| + | |||
| + | * Returns an integer. | ||
| + | * Only works on numeric values. | ||
| + | * Equivalent to Lua's bitwise NOT operator (<code>~</code>) in Cheat Engine. | ||
| + | * Useful for bitmask manipulation and logical inversions. | ||
| + | |||
| + | === Advanced Examples === | ||
| + | '''Inverting multiple flags:''' | ||
| + | |||
| + | <pre> | ||
| + | local flags = 0x0D -- 1101 | ||
| + | local inverted = bNot(flags) -- 0010 (if 4-bit context) | ||
| + | print(string.format("0x%X", inverted)) | ||
| + | </pre> | ||
| + | |||
| + | === See Also === | ||
| + | |||
| + | * [[Lua:bOr|bOr]] - Bitwise OR | ||
| + | * [[Lua:bXor|bXor]] - Bitwise XOR | ||
| + | * [[Lua:bAnd|bAnd]] - Bitwise AND | ||
| + | * [[Lua:bShl|bShl]] - Bitwise Shift Left | ||
| + | * [[Lua:bShr|bShr]] - Bitwise Shift Right | ||
| + | * [[Lua:bNot|bNot]] - Bitwise NOT | ||
Revision as of 14:58, 3 December 2025
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.
Contents
Function Parameters
| Parameter | Type | Description |
|---|---|---|
| int1 | integer | The value whose bits will be inverted. |
Returns
An integer representing the bitwise NOT of the input.
Description
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
Simple bitwise NOT:
print( bNot(0x0F) ) -- 0xF0 (in 8-bit context)
Using Lua's NOT operator (equivalent):
print( ~0x0F ) -- 0xF0 (in 8-bit context)
Clearing specific bits using NOT and AND:
local value = 0xFF
local mask = 0x0F
local cleared = bAnd(value, bNot(mask)) -- clears lower 4 bits
print(string.format("0x%X", cleared)) -- 0xF0
Behavior
- 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
Inverting multiple flags:
local flags = 0x0D -- 1101
local inverted = bNot(flags) -- 0010 (if 4-bit context)
print(string.format("0x%X", inverted))