Or simply do at the start
const unsigned char *localPtr = ptr;

Then use that for all your stepping and indexing.