[R] hex format

Duncan Murdoch murdoch at stats.uwo.ca
Thu Apr 7 16:49:01 CEST 2005

Steve Vejcik wrote:
> Thanks for your advice.  Unfortunately, your answers are inconsistent:
> as.numeric("0x1AF0") returns a decimal value for a hex string. I'd like
> to do the opposite-use hex notation to represent a decimal.
> e.g.
>     x<-0x000A
>     y<-0x0001
>     x+y=0x00B

R doesn't use decimal or hex values internally, it stores values in the 
native format (which is 64 bit floating point or 32 bit binary integers 
on most platforms).

You're talking about string conversions on input and output, which is a 
different issue.  R doesn't support C-style hex notation on input 
(though you can use "as.numeric" on input, as Brian said).

If you want an integer vector to always display in hex, assign a class 
to it and define a print method.  I don't think there's a standard 
library function to display in hex, but there are probably packages to 
do so.

Duncan Murdoch

More information about the R-help mailing list