Пример #1
0
        static BigInteger ToBigInteger(string value, int @base)
        {
            const string HEX = "0123456789ABCDEF";

            if (@base < 1 || @base > HEX.Length)
            {
                throw new ArgumentException("Base is out of range.");
            }

            BigInteger bi = BigInteger.Zero;

            foreach (char c in value)
            {
                char c2  = Char.ToUpper(c);
                int  idx = HEX.IndexOf(c2);
                if (idx == -1 || idx >= @base)
                {
                    throw new ArgumentOutOfRangeException("Illegal character encountered.");
                }
                bi = bi * @base + idx;
            }

            return(bi);
        }