Re: [R] hex format

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Fri 08 Apr 2005 - 00:49:01 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Apr 08 01:03:59 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:03 EST