0

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.

Adola
  • 1,909
  • 2
  • 13
  • 24

2 Answers2

7

How about you use the function?

$$f(x)=1-\frac{x}{255}$$

Harsh Kumar
  • 2,846
Alex Becker
  • 60,569
2

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.

franklin
  • 623
  • 13
  • 30