Skip to content

Instantly share code, notes, and snippets.

@Linux-cpp-lisp
Created January 6, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linux-cpp-lisp/8288518 to your computer and use it in GitHub Desktop.
Save Linux-cpp-lisp/8288518 to your computer and use it in GitHub Desktop.
A little function to take a value in the range 0-x and convert them to values in a different, smaller range.
unsigned int num_range_shrink(unsigned int orig, unsigned int old_limit, unsigned int new_upper) {
float interval = old_limit / new_upper;
for(int i = 1; i <= new_upper; i++) {
if(orig < i*interval) {
return i-1;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment