As a minor point, both uses like this: '4' <= *p && *p <= '7'
can be replaced with something like this: '4' <= *p and similarly, this: '0' <= c && c <= '3' can be replaced with this: c < '4' The replacements are not only shorter, but easier to understand, because otherwise the reader is left wondering why that unnecessary comparison to '7' (or '0') is in there.
