Quote Originally Posted by Salem
Or simply do at the start
const unsigned char *localPtr = ptr;

Then use that for all your stepping and indexing.
That's the best idea. Then you don't need all the casting.