示例#1
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> number converted from octal to binary.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [places].
        /// </para>
        /// <para>
        /// Number is the octal number you want to convert.
        /// Number may not contain more than 10 characters.
        /// The most significant bit of number is the sign bit.
        /// The remaining 29 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para>
        /// <para>
        /// Places is the number of characters to use.
        /// If places is omitted, OCT2BIN uses the minimum number of characters necessary.
        /// Places is useful for padding the return value with leading 0s (zeros).
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num3;

            base.CheckArgumentsLength(args);
            string s   = CalcConvert.ToString(args[0]);
            int    num = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToInt(args[1]) : 1;

            if (10 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((num < 1) || (10 < num))
            {
                return(CalcErrors.Number);
            }
            long number = EngineeringHelper.StringToLong(s, 8, out num3);

            if (num3 < s.Length)
            {
                return(CalcErrors.Number);
            }
            if ((number < -512L) || (0x1ffL < number))
            {
                return(CalcErrors.Number);
            }
            string str2 = EngineeringHelper.LongToString(number, 2L, (long)num);

            if (((0L <= number) && (num < str2.Length)) && CalcHelper.ArgumentExists(args, 1))
            {
                return(CalcErrors.Number);
            }
            return(str2);
        }
示例#2
0
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> number converted from hexadecimal to decimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: number.
        /// </para>
        /// <para>
        /// Number is the hexadecimal number you want to convert.
        /// Number cannot contain more than 10 characters (40 bits).
        /// The most significant bit of number is the sign bit.
        /// The remaining 39 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Object" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num2;

            base.CheckArgumentsLength(args);
            string s = CalcConvert.ToString(args[0]);

            if (10 < s.Length)
            {
                return(CalcErrors.Number);
            }
            long num = EngineeringHelper.StringToLong(s, 0x10, out num2);

            if (num2 < s.Length)
            {
                return(CalcErrors.Number);
            }
            return(CalcConvert.ToResult((double)num));
        }
示例#3
0
        /// <summary>
        /// Returns the <see cref="T:System.Int32" /> converted from binary to decimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: number.
        /// </para>
        /// <para>
        /// Number is the binary number you want to convert.
        /// Number cannot contain more than 10 characters (10 bits).
        /// The most significant bit of number is the sign bit.
        /// The remaining 9 bits are magnitude bits.
        /// Negative numbers are represented using two's-complement notation.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Int32" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            int num2;

            base.CheckArgumentsLength(args);
            string s = CalcConvert.ToString(args[0]);

            if (s.Length > 10)
            {
                return(CalcErrors.Number);
            }
            long num = EngineeringHelper.StringToLong(s, 2, out num2);

            if (s.Length > num2)
            {
                return(CalcErrors.Number);
            }
            return((int)CalcConvert.ToInt((long)num));
        }