I'm trying to write a PHP RGB-to-HEX converter and I'm trying to use a function to convert RGB numbers into letters if they're between 10 and 15 (and no, I can't use the "dechex()" function). This is how I have it coded right now:
function convToHex(&$hexInt)
{
switch($hexInt){
case 10:
$hexInt = "A";
break;
}
}
//create six hexadecimal variables for "hexMain"
$hex1 = intval($r / 16);
$hex2 = $r % 16;
$hex3 = intval($g / 16);
$hex4 = $g % 16;
$hex5 = intval($b / 16);
$hex6 = $b % 16;
$rgb = "#" . $r . $g . $b;
echo convToHex($hex1);
The problem is that when I try to echo it, the value just comes up as 0. What would be the best way to convert "$hex1", "$hex2", and so-on without using "dechex()"?
$r
,$g
,$b
, and when you return the functionconvToHex
?