I have cells for whom the numeric value can be anything between 0 and Integer.MAX_VALUE
. I would like to color code these cells correspondingly.
If the val
I could just do (value / (Integer.MAX_VALUE / 255)) but that will cause many low values to be zero.
One approach you could take is to use the modulo operator (r = value%256;
). Although this wouldn't ensure that it would guarantee a number between 0 and 255. It would also allow for low numbers to be distributed across the 0-255 range.Integer.MAX_VALUE
turns out as 255,
EDIT:
Funnily, as I test this, Integer.MAX_VALUE % 256
does result in 255
(I had originally mistakenly tested against %255
, which yielded the wrong results). This seems like a pretty straight forward solution.