This probably happens because the long is 32 bits on your machine and a signed long
can't hold 32 bits in 2's complement. You could try to use an unisgned
(which doesn't "waste" a bit for the sign) or a long long
which is 64 bits wide.
unsigned long x = strtoul(InputString, &pEnd, Base);
^^^^
Or long long
:
long long x = strtoll(InputString, &pEnd, Base);
The functions strtol
and strtoul
have been available for a long time in C++. Indeed strtoll
and long long
have been introduced in C++11.