[R] convert large integers to hex

Gabor Grothendieck ggrothendieck at gmail.com
Thu May 7 04:18:05 CEST 2009


rSymPy (http://rsympy.googlecode.com) can do that:

> library(rSymPy)
Loading required package: rJava
> sympy("hex(12345)")
[1] "0x3039"
> format.hexmode(as.numeric(12345))
[1] "3039"
> sympy("hex(6595137340052185552)")
[1] "0x5b86a277deb9a1d0L"

as can r-bc package (http://r-bc.googlecode.com - not on CRAN).

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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list