From ripley at stats.ox.ac.uk  Fri May 30 20:09:27 2008
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 30 May 2008 19:09:27 +0100 (BST)
Subject: [Rd] Reading an "unsigned long long" using R readBin()
In-Reply-To: <48404265.5060508@stats.uwo.ca>
References: <264855a00805291141s4d7537edkeda9b3ef3e627125@mail.gmail.com>
	<alpine.LFD.1.10.0805301850590.9386@gannet.stats.ox.ac.uk>
	<48404265.5060508@stats.uwo.ca>
Message-ID: <alpine.LFD.1.10.0805301907460.9537@gannet.stats.ox.ac.uk>

On Fri, 30 May 2008, Duncan Murdoch wrote:

> On 5/30/2008 1:55 PM, Prof Brian Ripley wrote:
>> Well, R has no unsigned quantities, so ultimately you can't actually do 
>> this.  But using what="int" and an appropriate 'size' (likely to be 8)
>> shold read the numbers, wrapping around very large ones to be negative.
>> (The usual trick of storing integers in numeric will lose accuracy, but 
>> might be better than nothing.)
>
> I think reading size 8 integers on 32 bit Windows returns signed 32 bit 
> integers, with values outside that range losing the high order bits, not just 
> accuracy.  At least that's what I see when I write the numbers 1:10 out as 4 
> byte integers, and read them as 8 byte integers:  I get 1 3 5 7 9.

Yes, that's true for even larger ones.

So to clarify: up to 2^31-1 should work, thereafter you will get the lower 
32 bits and hence possibly a signed number.

>
> Duncan Murdoch
>
>> 
>> On Thu, 29 May 2008, Sean Davis wrote:
>> 
>>> Sorry for the simple question, but I am trying to read an "unsigned
>>> long long" using the R readBin() function.  Can someone point me in
>>> the right direction, or am I better off using C for such things?  The
>>> file that I am reading will have been produced on the same machine
>>> that is doing the reading.
>>> 
>>> Thanks,
>>> Sean
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> 
>> 
>

-- 
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



[Rd] Reading an "unsigned long long" using R readBin()
Prof Brian Ripley