Hi,
well an example of an function which converts decimal to hexadecimal....
function convert_to_hexa($value) {
if ($value < 10)
return $value;
switch($value) {
case 10: return "A"; break;
case 11: return "B"; break;
case 12: return "C"; break;
case 13: return "D"; break;
case 14: return "E"; break;
case 15: return "F"; break;
}
return "INVALID";
}
function decimal_to_hexa($value) {
if ($value > 255)
return 0;
for ($i = 7; $i >= 0; $i--) {
if ($value & (1 << $i))
$binary[$i] = 1;
else
$binary[$i] = 0;
}
$first = 0;
for ($i = 7; $i >= 4; $i--) {
$first += ($binary[$i] (1 << $i));
}
$second = 0;
for ($i = 3; $i >= 0; $i--) {
$second += ($binary[$i] (1 << $i));
}
$first = convert_to_hexa($first);
$second = convert_to_hexa($second);
$total = "$first"."$second";
return $total;
}
Then just....
$r_value = decimal_to_hexa($r_value);
$g_value = decimal_to_hexa($g_value);
$b_value = decimal_to_hexa($b_value);
$color_string = "#$r_value$g_value$b_value";
I haven't tested the code above, but I hope that it is correct... otherwise I think you got the idea...
Good Luck