scanHexSequence method
index must point to the first hex digit. It will be advanced to point AFTER the hex sequence (i.e. index += count).
Implementation
int scanHexSequence(int count) {
int x = current;
int value = 0;
for (int i = 0; i < count; i++) {
if (char.$0 <= x && x <= char.$9) {
value = (value << 4) + (x - char.$0);
} else if (char.$a <= x && x <= char.$f) {
value = (value << 4) + (x - char.$a + 10);
} else if (char.$A <= x && x <= char.$F) {
value = (value << 4) + (x - char.$A + 10);
} else {
fail('Invalid hex sequence');
}
x = next();
}
return value;
}