Hi guys, I'm a C newbie (a couple of months ago I was a virgin!) working with PIC microcontroller s. I need to do a look-up table to change one value to another, probably best to give an example in pseudocode:
The last part I can deal with, and may not even be required (as you can see, the values in result[] are at intervals of 5, at least for the moment).
The tables will in reality have up to 100 entries. My plan was to iterate through reading[] and find when the number is bigger, then step back one. Is this OK, or is there a better way? Should I consider hash tables?
Code:
code const integer reading[5] ={12, 96, 147, 245, 747}; // sorted numerically code const integer result[5] ={5, 10, 15, 20, 25}; // sorted numerically get look-up value for reading[] (for example 120) find last value in reading[] below this (for example 96) return equivalent value from result[] (for example 10)
The tables will in reality have up to 100 entries. My plan was to iterate through reading[] and find when the number is bigger, then step back one. Is this OK, or is there a better way? Should I consider hash tables?
Comment