Skip to content
Back to formatted view

Raw Message

Message-ID: <16982.10720.352668.847676@stat.math.ethz.ch>
Date: 2005-04-08T06:51:12Z
From: Martin Maechler
Subject: hex format
In-Reply-To: <Pine.LNX.4.58.0504071544180.8199@maplepark.com>

>>>>> "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.