Difference between revisions of "Lua:byteTableToFloat"

From Cheat Engine
Jump to navigation Jump to search
m
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' byteTableToFloat(''Table'') ''':''' float
+
'''function''' byteTableToFloat(''Table'') ''':''' Number
  
Converts a byte table to a DWORD (4 bytes), interpreting them as a single precision floating point value.
+
Converts a table of bytes to a single precision (32-bit) floating point number.
  
 
+
===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 12: Line 11:
 
|-
 
|-
 
|Table
 
|Table
|table
+
|Table
|The table of bytes to convert
+
|A table containing the bytes to convert (least significant byte first).
 
|}
 
|}
  
 +
===Returns===
 +
Number — The resulting single precision floating point value.
  
== Examples ==
+
===Explanation===
Code:
+
The function takes a table of bytes (e.g., <code>{0xC3, 0xF5, 0x48, 0x40}</code>) and interprets them as a 32-bit float in little-endian order.
  local bt = { 0x00, 0x00, 0xC8, 0x42 }
 
  local value = byteTableToFloat(bt)
 
  print(string.format('0x%0X', value))
 
  print(value)
 
  
Output:
+
For example, <code>byteTableToFloat({0xC3, 0xF5, 0x48, 0x40})</code> returns <code>3.14</code>.
  0x64
 
  100.0
 
  
 +
===Examples===
 +
<pre>
 +
local floatValue = byteTableToFloat({0xC3, 0xF5, 0x48, 0x40})
 +
print(floatValue) -- Output: 3.14
 +
</pre>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Latest revision as of 17:40, 11 July 2025

function byteTableToFloat(Table) : Number

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]

local floatValue = byteTableToFloat({0xC3, 0xF5, 0x48, 0x40})
print(floatValue) -- Output: 3.14

See also[edit]

Related Functions[edit]