Bingxiang Miao
2008-Aug-22 01:51 UTC
[R] How I can read the binary file with "different type"?
Hi all, I have a binary file which have 8*100 bytes. The structure of the file is as follows: every eigth bytes represent 2 data:the first four bytes is the little-endian for integer, the next four bytes is the little-endian for floating32. The structure of the following bytes is as the same as the first eight bytes'. As the function readBin only read the binary file with one structure like this: readBin("my data file",what="integer",size=4,n=200) or readBin("my data file",what="numeric",size=4,n=200).But only one type of the data can be read properly. Can anyone suggest me how should I read this file? Thanks in advance. Miao [[alternative HTML version deleted]]
Moshe Olshansky
2008-Aug-22 03:36 UTC
[R] How I can read the binary file with "different type"?
Hi Miao, I can write a function which takes an integer and produces a float number whose binary representation equals to that of the integer, but this would be an awkward solution. So if nobody suggests anything better I will write such a function for you, but let's wait for a better solution. --- On Fri, 22/8/08, Bingxiang Miao <miao2007 at gmail.com> wrote:> From: Bingxiang Miao <miao2007 at gmail.com> > Subject: [R] How I can read the binary file with "different type"? > To: r-help at r-project.org > Received: Friday, 22 August, 2008, 11:51 AM > Hi all, > > I have a binary file which have 8*100 bytes. The > structure of the file is > as follows: every eigth bytes represent 2 data:the first > four bytes is the > little-endian for integer, the next four bytes is the > little-endian for > floating32. The structure of the following bytes is as the > same as the first > eight bytes'. > > As the function readBin only read the binary file with one > structure like > this: readBin("my data > file",what="integer",size=4,n=200) or > readBin("my > data file",what="numeric",size=4,n=200).But > only one type of the data can be > read properly. > > Can anyone suggest me how should I read this file? > > Thanks in advance. > > Miao > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code.
Prof Brian Ripley
2008-Aug-22 06:01 UTC
[R] How I can read the binary file with "different type"?
On Fri, 22 Aug 2008, Bingxiang Miao wrote:> Hi all, > > I have a binary file which have 8*100 bytes. The structure of the file is > as follows: every eigth bytes represent 2 data:the first four bytes is the > little-endian for integer, the next four bytes is the little-endian for > floating32. The structure of the following bytes is as the same as the first > eight bytes'. > > As the function readBin only read the binary file with one structure like > this: readBin("my data file",what="integer",size=4,n=200) or readBin("my > data file",what="numeric",size=4,n=200).But only one type of the data can be > read properly.That's plain wrong, and the examples on the help page disprove it. Please do read the help before posting. The concept is to use multiple readBin calls from an open connection (as in the examples on the help page).> Can anyone suggest me how should I read this file?We DO suggest you 'should' read the posting guide and the help pages.> > Thanks in advance. > > Miao > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595