[R] convert large integers to hex

Sundar Dorai-Raj sdorairaj at gmail.com
Thu May 7 14:53:01 CEST 2009


Thanks for both answers. In the end I decided to use Gabor's bc package.

Thanks,

--sundar

On Thu, May 7, 2009 at 5:10 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> There is an interface between R and bc -- not on CRAN but available
> from its home page here:
> http://r-bc.googlecode.com
>
>> source("http://r-bc.googlecode.com/svn/trunk/R/bc.R")
>> bc("obase = 16; 123456789123456789", retclass = "character")
> [1] "1B69B4BACD05F15"
>
>
> On Wed, May 6, 2009 at 9:59 PM, jim holtman <jholtman at gmail.com> wrote:
>> You can use the 'bc' command (use Cygwin if on Windows);
>>
>> /cygdrive/c: bc
>> bc 1.06
>> Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
>> This is free software with ABSOLUTELY NO WARRANTY.
>> For details type `warranty'.
>> x=6595137340052185552
>> obase=16
>> x
>> 5B86A277DEB9A1D0
>>
>> You can call this from R.
>>
>> On Wed, May 6, 2009 at 3:26 PM, Sundar Dorai-Raj <sdorairaj at gmail.com>wrote:
>>
>>> Hi,
>>>
>>> I'm wondering if someone has solved the problem of converting very
>>> large integers to hex. I know about format.hexmode and as.hexmode, but
>>> these rely on integers. The numbers I'm working with are overflowing
>>> and losing precision. Here's an example:
>>>
>>> x <- "6595137340052185552" # stored as character
>>> as.integer(x) # warning about inaccurate conversion
>>> format.hexmode(as.numeric(x)) # warnings about loss of precision
>>> as.hexmode(x) # more warnings and does not do what I expected
>>>
>>> I'm planning on writing a function that will do this, but would like
>>> to know if anybody already has a solution. Basically, I would like the
>>> functionality of format.hexmode on arbitrarily large integers.
>>>
>>> Thanks,
>>>
>>> --sundar
>>>
>>> ______________________________________________
>>> 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<http://www.r-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem that you are trying to solve?
>>
>>        [[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.
>>
>




More information about the R-help mailing list