Home > Back-end >  Converting Ranges of Values to a new Range
Converting Ranges of Values to a new Range

Time:10-16

So I am working on a small piece of code that involves a controller, but that isn't too important.

The problem I am having trouble with is that I am trying to convert an arbitrary number between the range of -32767 - 32768 to a range from 0 - 1.

How would I go about doing this?

Thanks in advance.

CodePudding user response:

To normalize a variable within a range, scale and shift the variable as follows:

amin, amax = -32767, 32768
x = (x- amin)/(amax-amin)
  • Related