Difference between revisions of "Lua:byteTableToDword"
Jump to navigation
Jump to search
m |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
− | '''function''' byteTableToDword(''Table'') ''':''' | + | '''function''' byteTableToDword(''Table'', [''Signed'']) ''':''' Number |
− | Converts a | + | Converts a table of bytes to a 32-bit dword (integer). |
− | + | ===Function Parameters=== | |
− | === Function Parameters === | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
− | {|width="85%" cellpadding="10 | ||
!align="left"|Parameter | !align="left"|Parameter | ||
!align="left"|Type | !align="left"|Type | ||
Line 12: | Line 11: | ||
|- | |- | ||
|Table | |Table | ||
− | | | + | |Table |
− | | | + | |A table containing the bytes to convert (least significant byte first). |
+ | |- | ||
+ | |Signed | ||
+ | |Boolean (optional) | ||
+ | |If true, returns a signed 32-bit integer. If false or omitted, returns an unsigned integer. | ||
|} | |} | ||
+ | ===Returns=== | ||
+ | Number — The resulting 32-bit dword (integer). | ||
+ | |||
+ | ===Explanation=== | ||
+ | The function takes a table of bytes (e.g., <code>{0x78, 0x56, 0x34, 0x12}</code>) and combines them into a single 32-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. | ||
− | + | For example, <code>byteTableToDword({0x78, 0x56, 0x34, 0x12})</code> returns <code>0x12345678</code> (305419896 in decimal). | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | Output: | + | ===Examples=== |
− | + | <pre> | |
− | + | local dword = byteTableToDword({0x78, 0x56, 0x34, 0x12}) | |
+ | print(dword) -- Output: 305419896 | ||
+ | -- Using signed interpretation | ||
+ | local signedDword = byteTableToDword({0xFF, 0xFF, 0xFF, 0xFF}, true) | ||
+ | print(signedDword) -- Output: -1 | ||
+ | </pre> | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} |
Latest revision as of 17:38, 11 July 2025
function byteTableToDword(Table, [Signed]) : Number
Converts a table of bytes to a 32-bit dword (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 32-bit integer. If false or omitted, returns an unsigned integer. |
Returns[edit]
Number — The resulting 32-bit dword (integer).
Explanation[edit]
The function takes a table of bytes (e.g., {0x78, 0x56, 0x34, 0x12}
) and combines them into a single 32-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, byteTableToDword({0x78, 0x56, 0x34, 0x12})
returns 0x12345678
(305419896 in decimal).
Examples[edit]
local dword = byteTableToDword({0x78, 0x56, 0x34, 0x12}) print(dword) -- Output: 305419896 -- Using signed interpretation local signedDword = byteTableToDword({0xFF, 0xFF, 0xFF, 0xFF}, true) print(signedDword) -- Output: -1
See also[edit]
Related Functions[edit]
- readBytes
- readSmallInteger
- readInteger
- readQword
- readPointer
- readFloat
- readDouble
- readString
- writeBytes
- writeSmallInteger
- 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
- byteTableToWord
- byteTableToDword
- byteTableToQword
- byteTableToFloat
- byteTableToDouble
- byteTableToString
- byteTableToWideString