[R] Binary file input to R

B.Rowlingson@lancaster.ac.uk B.Rowlingson at lancaster.ac.uk
Tue Jun 6 18:22:21 CEST 2000


> > I need to a binary data file consisting of 2 byte records, strip off the
> > upper 6 bits (using a logical AND, leaving a ten bit word), and then write
> > the ten bit number in text form for R.

 You could feed the binary file into 'od' with the appropriate
arguments:

$ od -v datafile | more
0000000 042577 043114 000401 000001 000000 000000 000000 000000
0000020 000002 000003 000001 000000 110460 004004 000064 000000
0000040 137244 000000 000000 000000 000064 000040 000006 000050
0000060 000032 000031 000006 000000 000064 000000 100064 004004
0000100 100064 004004 000300 000000 000300 000000 000005 000000
0000120 000004 000000 000003 000000 000364 000000 100364 004004
0000140 100364 004004 000023 000000 000023 000000 000004 000000
0000160 000001 000000 000001 000000 000000 000000 100000 004004

 Then read that into R as character strings (dump the first column).
Subscripting off the first 3 characters gets rid of 1+3+3 bits. A
bit too many. Can fix this by prepending a 1 if the 3rd character
of the 6-digit string is odd (that means bit 10 was set).

 Then convert to decimal by summing powers of 8...

 I think that makes sense...

Barry Rowlingson
Maths and Stats
Lancaster University
Lancaster, UK
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list