Difference between revisions of "Lua:byteTableToWord"
Jump to navigation
Jump to search
m |
m (Syntax Highlighting.) |
||
| Line 30: | Line 30: | ||
===Examples=== | ===Examples=== | ||
| − | < | + | <syntaxhighlight lang="lua" line> |
local word = byteTableToWord({0x39, 0x05}) | local word = byteTableToWord({0x39, 0x05}) | ||
print(word) -- Output: 1337 | print(word) -- Output: 1337 | ||
| Line 37: | Line 37: | ||
local signedWord = byteTableToWord({0xFF, 0xFF}, true) | local signedWord = byteTableToWord({0xFF, 0xFF}, true) | ||
print(signedWord) -- Output: -1 | print(signedWord) -- Output: -1 | ||
| − | </ | + | </syntaxhighlight> |
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
{{ReadWriteMemory}} | {{ReadWriteMemory}} | ||
Latest revision as of 15:48, 25 June 2026
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]
1 local word = byteTableToWord({0x39, 0x05})
2 print(word) -- Output: 1337
3
4 -- Using signed interpretation
5 local signedWord = byteTableToWord({0xFF, 0xFF}, true)
6 print(signedWord) -- Output: -1