Voting

: min(six, one)?
(Example: nine)

The Note You're Voting On

delchodimi at gmail dot com
10 years ago
I like the example with the bitwise operations but if the value of color[0] is less than 16 it's not accurate:
example:
color[0]: 0;
color[1]: 0;
color[2]: 255;
function hexColor($color) {
return dechex(($color[0]<<16)|($color[1]<<8)|$color[2]);
}
It returns "ff", which is not legit RGB color...
so my solution is to combine the function above with:
function toColor($n)
{
return("#".substr("000000".dechex($n),-6));
}

If you gotta deal with array of rgb values this is my solution:
------------------------------------------------------
function hexColor($color) {
$rgb = dechex(($color[0]<<16)|($color[1]<<8)|$color[2]);
return("#".substr("000000".$rgb, -6));
}
------------------------------------------------------

<< Back to user notes page

To Top