public static BigInteger Parse(string str)
{
BigInteger result = BigInteger.Zero;
bool negative = false;
int i = 0;
if (str[0] == '-')
{
negative = true;
i = 1;
}
else if (str[0] == '+')
i = 1;
for (; i < str.Length; i++)
{
char c = str[i];
if (c < '0' || c > '9')
throw new FormatException("Invalid character in number.");
result = MultiplyAdd(result, 10, c - '0');
}
if (result.wordCount != 1 || result.bits[0] != 0)
result.sign = negative == true ? -1 : 1;
return result;
}