# Continuous Data Map

*Data type change is important but how without significant data loss?*

## #

DescriptionIn any library we need to implement some mathematical features which might be useful in various ways in the rest of the library functions. One of those is a map function which maps a integer number from one data type to another ( a 32 bit un signed integer to a 8 bit un signed integer for instance). We can easily typecast values from a smaller datatype to a larger datatype without any data loss but if we do the reverse than some data goes out of memeory and thus results in either a loss of data or a wrong functioning due to wrong parameters ( which we seriously want to avoid in case of library functions).

So we create a map() function which maps a larger data type into a smaller one in uniform ratio of the ranges of the two types. Though we still can have some sought of data loss but the effect is greatly minimized. The function goes like this -

### #

A usage exampleWhile reading the data from analog pins and writing the same data to analog write we require to change the data from 32 bit un signed integer to 8 bit unsigned integer which is done using this function as shown below -