well i accidentally figured this out.. i have been looking for such a thing for a while so maybe it will help somebody else. it takes a Hex color value (e.g. FF66CC) and turns it into an RGB value (e.g. 255,102,204). Useful with things like the colored welcome messages in your chatrooms.
alias unhex {
var %l = 1, %r
while (%l <= $len($1-)) {
if (!$2) {
if ($mid($1-,%l,2) != 20) %r = %r $+ $chr($base($mid($1-,%l,2),16,10))
else %r = %r $chr($base($mid($1-,%l,2),16,10))
}
else %r = %r $+ $chr($base($mid($1-,%l,2),16,10))
inc %l 2
}
return %r
}
alias h2r {
var %h = $replace($1,00,zz)
var %c = 1
while ($right($left(%h,$calc(%c * 2)),2) != $null) {
var %m = $ifmatch
if (%m == zz) var %r = %r 0
else var %r = %r $asc($unhex(%m))
inc %c 1
if (%c = 4) break
}
return $replace(%r,$chr(32),$chr(44))
}
$h2r(FF66CC) returns 255,102,204
also, the reverse:
alias tohex {
var %l = 1, %r
while (%l <= $len($1-)) {
%r = %r $+ $base($asc($mid($1-,%l,1)),10,16,2)
inc %l
}
return %r
}
alias r2h {
:r2hok
if ($3) {
var %h = $tohex($chr($1))
var %h = %h $+ $tohex($chr($2))
var %h = %h $+ $tohex($chr($3))
}
else { tokenize 44 $1 | goto r2hok }
return $upper(%h)
}
$r2h(255,102,204) returns FF66CC
this works if you type in the 3 RGB values with commas or if you refer to an RGB value with a variable or identifier, either way.
*edit - i got the $unhex() and $tohex() aliases from Vincula
(thanks exo)