I've never seen color codes like -1
, -16777216
, -256
, etc. So my current problem is this:
We have a third-party software where you can color-code a value as illustrated in the picture below.
Now I'm creating a PHP report that displays those values but I also want to display them using the same colors as what is defined in the software. I was able to hunt the values down from the database but I'm confused as the values are in a format or notation that I'm not familiar with.
Could you help me convert these values to either HEX or RGB in either Oracle or PHP which is what I'm used to (I will use it for CSS for the report).
Looking at the database and the colors in the software I could at least match the numbers like so:
-1
= White
-12582784
= Purple
-65408
= Pink
-16777216
= Black
-256
= Yellow
So it looks like 16777216 is a perfect cube number. Its cube root is 256 (on RGB each primary color can be represented by a number from 0-255). So far that's the only relationship I can see think of. I still don't know how to convert that to HEX or RGB though.
I've done some research although not really fruitful. But I'll include it so I don't look like I didn't make an attempt - if you're not interested in it then just ignore it:
16777216 - I started by searching the actual code -16777216
but that didn't return anything so I removed the negative sign.
Facts about 16777216 - that page shows some formulas but I didn't see any that converts to HEX or RGB.
Your colours are indeed RGB values stored in a slightly twisted way. All you have to do is, take the decimal number away from 16777216 and convert to HEX.
16777216-1 = 16777215 (FFFFFFh = White)
16777216-12582784 = 4194432 (400080h = Purple)
16777216-65408 = 16711808 (FF0080h = Pink)
16777216-16777216 = 0 (000000h = Black)
16777216-256 = 16776960 (FFFF00h = Yellow)
I hope this helps. Apologies for not writing a code, but I am afraid I am not quite there yet in my studies. I promise I will work on it when I get there. :)
I suggest using PHP to pull the BACK_COLOR (i.e. "coded color reference id") into each table cell. Prefix that negative number with a character for CSS reasons. Include CSS that specifies the color per dynamic class.
<style>
.g-1 { color: #000; background: #ffffff /* white */ }
.g-12582784 { color: #fff; background: #3F0180 /* purple */ }
.g-65408 { color: #fff; background: #FF0080 /* pink */ }
.g-256 background: { color: #000; #FFFD05 /* yellow */ }
.g-16777216 { color: #fff; background: #000000 /* black */ }
</style>
<table>
<tr>
<td class="g-12582784">Option 1</span> <!-- use PHP to generate this class -->
<td class="g-65408">Option 2</span> <!-- use PHP to generate this class -->
<td class="g-256">Option 3</span> <!-- use PHP to generate this class -->
</tr>
</table>
In PHP I created this function thanks to this note.
function toColor($n) {
return ("#".substr("000000".dechex($n),-6));
}
It converts the signed int to hex and it looks like the colors match. On a separate quest I want to reduce the alpha channel down because the colors are very strong but I'll save that for another day.