# normalize int data

This is a discussion on normalize int data within the C# Programming forums, part of the General Programming Boards category; Hello everyone, I have a couple of integers, and I want to find a simple and effective way to normalize ...

1. ## normalize int data

Hello everyone,

I have a couple of integers, and I want to find a simple and effective way to normalize them into range [0, 1]. Any ideas and code refer?

thanks in advance,
George

2. Not sure what you mean. If you mean map from one interval to another, then something like this:
Code:
```int Min = //Minimum value in your interval
int Max = //Maximum value in your interval
int Value = //Value to normalize, maybe from traversing an array

double NormalizedValue = (double)(Value - Min) / (double)(Max - Min);```
(just be sure that Max > Min)

Using this, in the interval 1 - 5, 1 would map to 0.0, 5 would map to 1.0 and 3 would map to 0.5.

3. Thanks Magos,

I heard there is also a logarithm based normalization approach, do you know how to implement in this way?

Originally Posted by Magos
Not sure what you mean. If you mean map from one interval to another, then something like this:
Code:
```int Min = //Minimum value in your interval
int Max = //Maximum value in your interval
int Value = //Value to normalize, maybe from traversing an array

double NormalizedValue = (double)(Value - Min) / (double)(Max - Min);```
(just be sure that Max > Min)

Using this, in the interval 1 - 5, 1 would map to 0.0, 5 would map to 1.0 and 3 would map to 0.5.

regards,
George

Popular pages Recent additions