Converting RGB values in 0-255 format to values in 0.0f-1.0f format

You guys need to actually test that code before posting it because the integer math will destroy your results.



int x = 127;

float newX = x / 255



newX == 0



You’d have to turn one of the operands into a float in order to get a float divide.

float newX = x / 255f;



…for example. And x = 0 is not a consideration here if the math is done right. 0 / 255f == 0

6 Likes