[R] hex format
Martin Maechler
maechler at stat.math.ethz.ch
Fri Apr 8 08:51:12 CEST 2005
>>>>> "David" == David Forrest <drf5n at maplepark.com>
>>>>> on Thu, 7 Apr 2005 16:19:33 -0500 (CDT) writes:
....
David> I think R has the hex to decimal OK, but might be
David> lacking in the decimal to hex case
David> zz<-function(x){ x<-as.numeric(sub("#",'0x',x));
David> c(x%/%256^2, x%/%256%%256, x%%256) }
>> zz('#0f0e0d')
David> [1] 15 14 13
>> zz('#ff0080')
David> [1] 255 0 128
I think you have overlooked the col2rgb() function
which does this (and more).
David> If you already have the 3 byte triplet in read in as
David> a binary, the same integer arithmetic does the
David> extraction.
More information about the R-help
mailing list