Difference between revisions of "Lua:byteTableToFloat"
Jump to navigation
Jump to search
m |
m (Syntax Highlighting.) |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' byteTableToFloat(''Table'') ''':''' Number | + | {{CodeBox|'''function''' byteTableToFloat(''Table'') ''':''' Number}} |
Converts a table of bytes to a single precision (32-bit) floating point number. | Converts a table of bytes to a single precision (32-bit) floating point number. | ||
| Line 24: | Line 24: | ||
===Examples=== | ===Examples=== | ||
| − | < | + | <syntaxhighlight lang="lua" line> |
local floatValue = byteTableToFloat({0xC3, 0xF5, 0x48, 0x40}) | local floatValue = byteTableToFloat({0xC3, 0xF5, 0x48, 0x40}) | ||
print(floatValue) -- Output: 3.14 | print(floatValue) -- Output: 3.14 | ||
| − | </ | + | </syntaxhighlight> |
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | |||
{{ReadWriteMemory}} | {{ReadWriteMemory}} | ||
Latest revision as of 15:48, 25 June 2026
Converts a table of bytes to a single precision (32-bit) floating point number.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| Table | Table | A table containing the bytes to convert (least significant byte first). |
Returns[edit]
Number — The resulting single precision floating point value.
Explanation[edit]
The function takes a table of bytes (e.g., {0xC3, 0xF5, 0x48, 0x40}) and interprets them as a 32-bit float in little-endian order.
For example, byteTableToFloat({0xC3, 0xF5, 0x48, 0x40}) returns 3.14.
Examples[edit]
1 local floatValue = byteTableToFloat({0xC3, 0xF5, 0x48, 0x40})
2 print(floatValue) -- Output: 3.14