Difference between revisions of "Lua:byteTableToWord"

From Cheat Engine
Jump to navigation Jump to search
m (Added CodeBox Template.)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''function''' byteTableToWord(''Table'') ''':''' integer
+
[[Category:Lua]]
 +
{{CodeBox|'''function''' byteTableToWord(''Table'', [''Signed'']) ''':''' Number}}
  
Converts a byte table to a WORD (2 bytes), interpreting them as an integer.
+
Converts a table of bytes to a 16-bit word (integer).
  
 
+
===Function Parameters===
=== Function Parameters ===
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
 
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 11: Line 11:
 
|-
 
|-
 
|Table
 
|Table
|table
+
|Table
|The table of bytes to convert
+
|A table containing the bytes to convert (least significant byte first).
 +
|-
 +
|Signed
 +
|Boolean (optional)
 +
|If true, returns a signed 16-bit integer. If false or omitted, returns an unsigned integer.
 
|}
 
|}
  
 +
===Returns===
 +
Number — The resulting 16-bit word (integer).
 +
 +
===Explanation===
 +
The function takes a table of bytes (e.g., <code>{0x39, 0x05}</code>) and combines them into a single 16-bit value. 
 +
The first element is the least significant byte (little-endian order). 
 +
If <code>Signed</code> is true, the result is interpreted as a signed integer.
  
== Examples ==
+
For example, <code>byteTableToWord({0x39, 0x05})</code> returns <code>1337</code>.
Code:
 
  local bt = { 0x64, 0x00 }
 
  local value = byteTableToWord(bt)
 
  print(string.format('0x%0X', value))
 
  print(value)
 
  
Output:
+
===Examples===
  0x64
+
<pre>
  100
+
local word = byteTableToWord({0x39, 0x05})
 +
print(word) -- Output: 1337
  
 +
-- Using signed interpretation
 +
local signedWord = byteTableToWord({0xFF, 0xFF}, true)
 +
print(signedWord) -- Output: -1
 +
</pre>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua]]
 
* [[Help_File:Script engine|Script engine]]
 
  
 
=== Related Functions ===
 
=== Related Functions ===
* [[readBytes]]
+
{{ReadWriteMemory}}
* [[readInteger]]
 
* [[readQword]]
 
* [[readPointer]]
 
* [[readFloat]]
 
* [[readDouble]]
 
* [[readString]]
 
* [[writeBytes]]
 
* [[writeInteger]]
 
* [[writeQword]]
 
* [[writeFloat]]
 
* [[writeDouble]]
 
* [[writeString]]
 
* [[readBytesLocal]]
 
* [[readIntegerLocal]]
 
* [[readQwordLocal]]
 
* [[readPointerLocal]]
 
* [[readFloatLocal]]
 
* [[readDoubleLocal]]
 
* [[readStringLocal]]
 
* [[writeBytesLocal]]
 
* [[writeIntegerLocal]]
 
* [[writeQwordLocal]]
 
* [[writeFloatLocal]]
 
* [[writeDoubleLocal]]
 
* [[writeStringLocal]]
 
* [[wordToByteTable]]
 
* [[dwordToByteTable]]
 
* [[qwordToByteTable]]
 
* [[floatToByteTable]]
 
* [[doubleToByteTable]]
 
* [[stringToByteTable]]
 
* [[wideStringToByteTable]]
 
* [[byteTableToDword]]
 
* [[byteTableToQword]]
 
* [[byteTableToFloat]]
 
* [[byteTableToDouble]]
 
* [[byteTableToString]]
 
* [[byteTableToWideString]]
 

Latest revision as of 23:11, 4 December 2025

<> Function

function byteTableToWord(Table, [Signed]) : Number

Converts a table of bytes to a 16-bit word (integer).

Function Parameters[edit]

Parameter Type Description
Table Table A table containing the bytes to convert (least significant byte first).
Signed Boolean (optional) If true, returns a signed 16-bit integer. If false or omitted, returns an unsigned integer.

Returns[edit]

Number — The resulting 16-bit word (integer).

Explanation[edit]

The function takes a table of bytes (e.g., {0x39, 0x05}) and combines them into a single 16-bit value. The first element is the least significant byte (little-endian order). If Signed is true, the result is interpreted as a signed integer.

For example, byteTableToWord({0x39, 0x05}) returns 1337.

Examples[edit]

local word = byteTableToWord({0x39, 0x05})
print(word) -- Output: 1337

-- Using signed interpretation
local signedWord = byteTableToWord({0xFF, 0xFF}, true)
print(signedWord) -- Output: -1

See also[edit]

Lua
Script Engine

Related Functions[edit]

Read Functions
readBytes
readSmallInteger
readInteger
readQword
readPointer
readFloat
readDouble
readString
Read Functions (Local Process)
readBytesLocal
readIntegerLocal
readQwordLocal
readPointerLocal
readFloatLocal
readDoubleLocal
readStringLocal
Write Functions
writeBytes
writeSmallInteger
writeInteger
writeQword
writeFloat
writeDouble
writeString
Write Functions (Local Process)
writeBytesLocal
writeIntegerLocal
writeQwordLocal
writeFloatLocal
writeDoubleLocal
writeStringLocal
Byte Table Conversions (Value → Byte Table)
wordToByteTable
dwordToByteTable
qwordToByteTable
floatToByteTable
doubleToByteTable
stringToByteTable
wideStringToByteTable
Byte Table Conversions (Byte Table → Value)
byteTableToWord
byteTableToDword
byteTableToQword
byteTableToFloat
byteTableToDouble
byteTableToString
byteTableToWideString