Difference between revisions of "Lua:byteTableToDword"
Jump to navigation
Jump to search
m (Added CodeBox Template.) |
m (Syntax Highlighting.) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 30: | Line 30: | ||
===Examples=== | ===Examples=== | ||
| − | < | + | <syntaxhighlight lang="lua" line> |
local dword = byteTableToDword({0x78, 0x56, 0x34, 0x12}) | local dword = byteTableToDword({0x78, 0x56, 0x34, 0x12}) | ||
print(dword) -- Output: 305419896 | print(dword) -- Output: 305419896 | ||
| Line 37: | Line 37: | ||
local signedDword = byteTableToDword({0xFF, 0xFF, 0xFF, 0xFF}, true) | local signedDword = byteTableToDword({0xFF, 0xFF, 0xFF, 0xFF}, true) | ||
print(signedDword) -- Output: -1 | print(signedDword) -- Output: -1 | ||
| − | </ | + | </syntaxhighlight> |
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | |||
{{ReadWriteMemory}} | {{ReadWriteMemory}} | ||
Latest revision as of 15:48, 25 June 2026
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]
1 local dword = byteTableToDword({0x78, 0x56, 0x34, 0x12})
2 print(dword) -- Output: 305419896
3
4 -- Using signed interpretation
5 local signedDword = byteTableToDword({0xFF, 0xFF, 0xFF, 0xFF}, true)
6 print(signedDword) -- Output: -1