[R] converting decimal - hexadecimal

Earl F. Glynn efg at stowers-institute.org
Wed Aug 30 16:40:25 CEST 2006


"Romain Lorrilliere" <romain.lorrilliere at ese.u-psud.fr> wrote in message 
news:451E7762.8000307 at ese.u-psud.fr...
Hi,

do you know, a method to convert an decimal value (integer) to the
corresponding hexadecimal value ?

Starting in R 2.1.0, sprintf can be used:

> x <- c(0, 65535, 65536, 305419896, 2^31-1)
> y <- sprintf("0x%X", x)
> y
[1] "0x0"        "0xFFFF"     "0x10000"    "0x12345678" "0x7FFFFFFF"
> as.numeric(y)
[1]          0      65535      65536  305419896 2147483647

efg

Earl F. Glynn
Scientific Programmer
Stowers Institute for Medical Research



More information about the R-help mailing list