# convert 0-255 into decimal between 0-1 [closed]

What I am trying to do is convert the color values 0-255 into a decimal form between 0-1 for example 127.5 = 0.50 or 191.25 = 0.75. I know this is simple math but the problem is that with the program I am writing a 0 represents ON and a 1 represents OFF so with a color code of 255 it should actually be equal to 0.0 and with a color code value of 0 it should equal 1.0. Can someone please tell me how to solve this math has never been a strong point of mine.

-

## closed as off topic by Jim, Micah, Asaf Karagila, Alexander Gruber♦, Chris EagleFeb 24 '13 at 22:08

Questions on Mathematics Stack Exchange are expected to relate to math within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Shouldn't this be on StackOverflow, not Mathematics? – AJMansfield Feb 24 '13 at 20:26
I posed this on StackOverflow and actually got the same answer as below but for some reason I guess I was not doing the equation right and kept coming up with the wrong answer. – Yamaha32088 Feb 24 '13 at 20:27
So you both posted in the wrong place, AND double posted. – AJMansfield Feb 24 '13 at 20:29
That would be correct – Yamaha32088 Feb 24 '13 at 20:31

How about you use the function $f(x)=1-x/255$?
All you need really is $f(x) = x/255$ for example if you put the input color as $x$ your output should be $f(x)$ as in, $x = 127.5$, $f(x) = 0.5$. It's a proportion of your input value to the entire spectrum, 255.