[R] readBin which has two different sizes

Ab Hu master.rstat at yahoo.com
Sun Oct 3 19:59:50 CEST 2010


Hi,
I have a binary file which has the following structure:
1) Some header in the beginning
2) Thousands of 216-byte data sub-grouped into 4 54-byte data structured as
4-byte time stamp (big endian) followed by 50 1-byte (8-bit) samples.

So far this is how I am trying:
#Open a connection for binary file
to.read <- file("binary file", "rb")       

#Read header
info <- readBin(to.read, character(),1)

#Read data: byte=1, n=number of data (i know this from header) * 216 (bytes
per data)
data <- readBin(to.read, integer(), size=1, n=35269*216, signed=TRUE, endian
= "big")

I am able to read the header but obviously having trouble in that last line
because my data has two sizes; 4-byte time stamp and one byte (8-bit)
samples. Also, one is unsigned and other is signed.

How do i read these two differently sized, signed data?
Would appreciate any help, thanks.
-- 
View this message in context: http://r.789695.n4.nabble.com/readBin-which-has-two-different-sizes-tp2953365p2953365.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list