Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leia #1

Open
MegamiSyn opened this issue Oct 20, 2017 · 1 comment
Open

leia #1

MegamiSyn opened this issue Oct 20, 2017 · 1 comment

Comments

@MegamiSyn
Copy link

float para hex
https://gregstoll.dyndns.org/~gregstoll/floattohex/

ex 2.296883 float to hex 0x40130020

x=0x40130020
s=string.pack("i4",x)
f=string.unpack("f",s)
print(f)

vai imprimir 2.2968826293945

fonte https://stackoverflow.com/questions/29592951/lua-hex-to-float
https://stackoverflow.com/questions/18886447/convert-signed-ieee-754-float-to-hexadecimal-representation

@nathan130200
Copy link

nathan130200 commented Apr 9, 2020

Tem o string pack/unpack do formato n. Fiz um teste e de primeira funcionou algo do tipo:

local src = 2.296883

local temp = string.pack("n", src)
print(temp)

local res = string.unpack("n", temp)
print(res)

print("iguais?? " .. tostring(res == src))

Output:

-�1�`�@
2.296883
iguais?? true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants