Appologies! I only quickly looked over it If I had a larger array I would certainly investigate this method... I'm intrigued to see how a tiny microcontroller would cope with this kind of search!
OK, then you can go really funky. Using something like this:
struct lookup
{
int num;
unsigned char rank;
}
struct lookup vals[] =
{
{4185, 4},
{4507, 3},
{4883, 2},
{5327, 1},
{MAX, 0}
}
If you make the array size a power of two you should be able to implement the binary search with bit manipulation using |= and <<. Or you can start somewhere in the middle of the array with an index that is power of two and see that you don't go over the highest index.
greets,
Staf.