Hi I am wanting to map a particular range of numbers to a different range in objective C for an iPad application.
For example I may have an input value in the range 0-255 but I want to output to be in the range 0.5-1. For example, an input of 127.5 would result in an output of 0.75.
Cheers in advance.
Here's the general solution (it should work for any combination of ranges and input values):
CGFloat const inMin = 0.0;
CGFloat const inMax = 255.0;
CGFloat const outMin = 0.5;
CGFloat const outMax = 1.0;
CGFloat in = 127.5;
CGFloat out = outMin + (outMax - outMin) * (in - inMin) / (inMax - inMin);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With