lua-users home
lua-l archive

Re: Parse 12 bit numbers from binary file

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


чт, 4 июл. 2019 г. в 19:02, Russell Haley <russ.haley@gmail.com>:
> The file I am trying to read is here:
>
> https://physionet.org/pn3/twadb/twa00.dat
>
> When I use the existing tool to read the data out I get the following:
>
> 0 -298 127
> 1 -295 132
> 2 -292 137
> 3 -293 141
> 4 -295 145
> 5 -295 149
> 6 -293 153
> 7 -290 160
> 8 -286 167
> 9 -283 176
>
1) file must be binary
2) your file contains pairs of 16bit integers
f=io.open("twa00.dat","rb")
s=f:read"*all"
f:close()
for i=1,#s,4 do
 a,b=string.unpack("<i2i2",s,i)
 print(a,b)
end

AltStyle によって変換されたページ (->オリジナル) /