[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: IEEE-754 encode/decode
- From: Tim Channon <tc@...>
- Date: Sun, 28 Mar 2010 14:32:08 +0100
Clark Snowdall wrote:
> Hello all,
>
> I'm a newbie here so be gentle ...
>
> I need to convert back and forth between a string of bytes (4 bytes,
> 32-bits), and IEEE-754 floating point. Basically I need to read a
> byte stream from a network socket and convert those bytes to a
> number.
There is the tiny Struct library (8.4k of c source) by the authors of
Lua which might help but gives a different answer on this computer, so
maybe it is using a different fp standard.
http://www.inf.puc-rio.br/~roberto/struct/
require("struct")
x = string.char(0x42, 0x96, 0x00, 0x00)
ans=struct.unpack(">!32f",x) -- big endian 32bit float
print(ans)
75