# Take set of values and change scale [duplicate]

I have a large array of variable-integer keypairs. The integer values range from -5 to 5. I'd like to scale that data to a range of 0 to 2. Logically, -5 would become 0, 0 would become 1 and 5 would become 2. How should I go about doing this on a large scale and with different input ranges?

-

## marked as duplicate by Rahul, Stefan Hansen, AWertheim, O.L., Dennis GulkoJun 7 '13 at 7:21

If $x$ ranges from $a$ to $b$, then $x-a$ ranges from $0$ to $b-a$, so $(x-a)/(b-a)$ ranges from $0$ to $1$, so $(d-c)(x-a)/(b-a)$ ranges from $0$ to $d-c$, so $${(d-c)(x-a)\over b-a}+c$$ ranges from $c$ to $d$.
Work through what I wrote: $x$ ranges from -5 to 5, $x+5$ ranges from 0 to 10, $(x+5)/(5-(-5))$ ranges from 0 to 1, $(2-0)(x+5)/10$ ranges from 0 to 2, voila! –  Gerry Myerson Jun 17 '12 at 2:00