Difference between revisions of "Lua:signExtend"

From Cheat Engine
Jump to navigation Jump to search
(Initial page creation.)
 
m (Examples: Syntax Highlight.)
 
Line 25: Line 25:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
local value = signExtend(0x7F, 7)
 
local value = signExtend(0x7F, 7)
  
 
print(value)
 
print(value)
 
-- 127
 
-- 127
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local value = signExtend(0x80, 7)
 
local value = signExtend(0x80, 7)
  
 
print(value)
 
print(value)
 
-- -128
 
-- -128
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local value = signExtend(0xFF, 7)
 
local value = signExtend(0xFF, 7)
  
 
print(value)
 
print(value)
 
-- -1
 
-- -1
</pre>
+
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Latest revision as of 23:26, 26 June 2026

<> Lua API Reference

function signExtend(value, mostSignificantBit) : integer

Sign-extends the given value.

If the specified most significant bit is set, the value will be extended as a negative signed integer. If the bit is not set, the value remains positive.

Function Parameters[edit]

Parameter Type Description
value Integer The value to sign-extend.
mostSignificantBit Integer The bit index to treat as the most significant sign bit.

Returns[edit]

integer — The sign-extended integer value.

Examples[edit]

1 local value = signExtend(0x7F, 7)
2 
3 print(value)
4 -- 127
1 local value = signExtend(0x80, 7)
2 
3 print(value)
4 -- -128
1 local value = signExtend(0xFF, 7)
2 
3 print(value)
4 -- -1

Main Pages

Core Lua documentation entry points

Lua
Script Engine