Reading binary file bitwise in R

牧云@^-^@ 提交于 2019-12-24 15:26:02

问题


Since I am not a programmer I got stuck solving this probably trivial problem: I would like to extract numeric values from binary file (example.Lis) using R. First 256 bytes contain a header. I know the header structure therefore I was able to decode its content. For instance, according the format description, OLE DATE information is stored in bytes 8-15 as a double data type. To read this, I simply used following command:

my.file = file("example.Lis", "rb")
headall<-readBin(my.file, raw(), n=256, size=1)
readBin(headall[9:16],double(),size=8,n=1)

[1] 42438.66

Header is followed by a series of 32-bit data records. Each record contain multiple integer values, so it is not possible to proceed byte-wise as in the header case. Is it somehow possible to read the file bit-wise to decode the numbers inside each record?

As the format description states (page 4), 32-bit words are encoded as follows:

来源:https://stackoverflow.com/questions/35919472/reading-binary-file-bitwise-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!