Difference between revisions of "Lua:doubleToByteTable"

From Cheat Engine
Jump to navigation Jump to search
m
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' doubleToByteTable(''Number'') ''':''' table
+
'''function''' doubleToByteTable(''Number'') ''':''' Table
  
Converts a QWORD (8 bytes), interpreted as a double precision floating point, to a byte table.
+
Converts a double precision (64-bit) floating point number to a table of bytes.
  
 
+
===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:
 
|-
 
|-
 
|Number
 
|Number
|number
+
|Number
|The number to convert to a byte table
+
|The double precision floating point value to convert.
 
|}
 
|}
  
 +
===Returns===
 +
Table — A table containing the bytes representing the double.
  
== Examples ==
+
===Examples===
  local bt = doubleToByteTable(100.0)
+
<pre>
  writeBytes('00123ABC', bt)
+
local bytes = doubleToByteTable(3.1415926535)
 
+
for i, b in ipairs(bytes) do
 
+
  print(string.format("Byte %d: %02X", i, b))
Code:
+
end
  local bt = doubleToByteTable(10)
+
-- Output: 8 bytes representing the double in little-endian order
  for i, v in ipairs(bt) do
+
</pre>
    print(i - 1, string.format('%02X', v))
 
  end
 
 
 
Output:
 
  0 00
 
  1 00
 
  2 00
 
  3 00
 
  4 00
 
  5 00
 
  6 24
 
  7 40
 
 
 
 
 
Code:
 
  local bt = doubleToByteTable(10.9)
 
  for i, v in ipairs(bt) do
 
    print(i - 1, string.format('%02X', v))
 
  end
 
 
 
Output:
 
  0 CD
 
  1 CC
 
  2 CC
 
  3 CC
 
  4 CC
 
  5 CC
 
  6 25
 
  7 40
 
 
 
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}

Revision as of 17:26, 11 July 2025

function doubleToByteTable(Number) : Table

Converts a double precision (64-bit) floating point number to a table of bytes.

Function Parameters

Parameter Type Description
Number Number The double precision floating point value to convert.

Returns

Table — A table containing the bytes representing the double.

Examples

local bytes = doubleToByteTable(3.1415926535)
for i, b in ipairs(bytes) do
  print(string.format("Byte %d: %02X", i, b))
end
-- Output: 8 bytes representing the double in little-endian order

See also

Related Functions