[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Read ieee-754-2008 four-byte floating-point number from binary file?
- From: Tim Channon <tc@...>
- Date: Sat, 17 Apr 2010 01:26:29 +0100
Luis Carvalho wrote:
>> I'm reading some files in an existing binary format, which include 4-byte
>> floating-point numbers. I have the file's contents loaded into a string. I
>> need a function which will parse one floating-point number from the string,
>> given the index of the first byte. Does Lua's library provide this? Or
>> should I throw something together with the bitop library?
>
> Take a look at Roberto's struct library,
>
> http://www.inf.puc-rio.br/~roberto/struct/
>
> or LHF's lpack,
>
> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/
>
> Using the former:
>
> $ lua -lstruct -e 'print(struct.unpack("f", struct.pack("f", math.pi), 1))'
> 3.1415927410126 5
Binary data published by RSS is literally read using struct and the
result is eg.
http://daedalearth.files.wordpress.com/2010/04/channel_tlt_tb_anom_v03_2_201003.png?w=480&h=360
Apart from plotting, all Lua. Pipe control of gnuplot. Local data in
sqlite3 using lsqlite
Ain't neat, horrible hack but it works. The data for that was FTP
download using luasocket too.