Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question

closed as off topic by Jim, Micah, Asaf Karagila, Alexander Gruber, Chris Eagle Feb 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
up vote 7 down vote accepted

How about you use the function $f(x)=1-x/255$?

share|cite|improve this answer
this works for 127.5 but for 191.25 you would get 0.25. the subtraction from 1 is not necessary. – franklin Feb 24 '13 at 20:21
the 0.25 for 191.25 is what I actually want in this case it seems strange and backwards I know – Yamaha32088 Feb 24 '13 at 20:24
@franklin That is the OP's intent behavior, so the subtraction from 1 is in fact necessary to perform the OP's task. – AJMansfield Feb 24 '13 at 20:24
ah. thanks @AJMansfield. actually then this would be the correct answer. – franklin Feb 24 '13 at 20:24
thanks a lot I will accept answer when time allows – Yamaha32088 Feb 24 '13 at 20:29

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.

share|cite|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.