Beispiel #1
0
        private void SetInteger(Radix radix, string s)
        {
            var intBase = radix == Radix.Binary ? 2 : (radix == Radix.Decimal ? 10 : 16);

            if (radix.IsInt(s))
            {
                _v.IntValue = Convert.ToInt32(s, intBase);
                return;
            }

            if (radix.IsLong(s))
            {
                _v.LongValue = Convert.ToInt64(s, intBase);
                return;
            }

            //bigint
            if (intBase == 10)
            {
                _v.BigIntegerValue = BigInteger.Parse(s);
                return;
            }

            if (intBase == 16)
            {
                _v.BigIntegerValue = BigInteger.Parse(s, NumberStyles.HexNumber);
                return;
            }

            //does anyone really do this?
            SetBigIntegerFromBinaryString(s);
        }
        private void SetInteger(Radix radix, string s, bool negative)
        {
            var intBase = radix == Radix.Binary ? 2 : (radix == Radix.Decimal ? 10 : 16);

            if (radix.IsInt(s.AsSpan()))
            {
                _v.IntValue = negative ? -Convert.ToInt32(s, intBase) : Convert.ToInt32(s, intBase);
                return;
            }

            if (radix.IsLong(s.AsSpan()))
            {
                _v.LongValue = negative ? -Convert.ToInt64(s, intBase) : Convert.ToInt64(s, intBase);
                return;
            }

            //bigint
            if (intBase == 10)
            {
                _v.BigIntegerValue = negative
                    ? -BigInteger.Parse(s, CultureInfo.InvariantCulture)
                    : BigInteger.Parse(s, CultureInfo.InvariantCulture);
                return;
            }

            if (intBase == 16)
            {
                _v.BigIntegerValue = negative
                    ? -BigInteger.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture)
                    : BigInteger.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
                return;
            }

            //does anyone really do this?
            SetBigIntegerFromBinaryString(s, negative);
        }