Objective c map one number range to another
ios5, iphone, objective-c
Solution
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);
Problem
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.