Logic behind 255 in Uicolor

advertisements

We generally write 143.0/255.0 in UIColor setcolor RGB arguements . Can anybody pl tel me the logic behind Dividing by 255.0 . I have some knowledge but i guess it is incomplete.


Most Core Graphic APIs expect the RGB color components to be in the range of 0.0 to 1.0. However many computer color palettes and Mac output devices expect RGB color components to be representable in 8 bit values, which, when expressed as integers, are in the range of 0 to 255.

If you are looking up a color from a table with 8-bit component values (e.g. a web color of #RRGGBB), then you need to scale the values from the range 0 to 255 to the range 0 to 1.0, which is done by dividing by 255.0f (in floating point, so you don't end up truncating to 0).