Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> converted from decimal to hexadecimal.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 2 items: number, [places].
        /// </para>
        /// <para>
        /// Number is the decimal integer you want to convert.
        /// If number is negative, places is ignored and DEC2HEX returns
        /// a 10-character (40-bit) hexadecimal number in which the most significant bit is the sign bit.
        /// The remaining 39 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, DEC2HEX 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)
        {
            base.CheckArgumentsLength(args);
            long number = CalcConvert.ToLong(args[0]);
            int  num2   = CalcHelper.ArgumentExists(args, 1) ? CalcConvert.ToInt(args[1]) : 1;

            if ((number < -549755813888L) || (0x7fffffffffL < number))
            {
                return(CalcErrors.Number);
            }
            if ((num2 < 1) || (10 < num2))
            {
                return(CalcErrors.Number);
            }
            string str = EngineeringHelper.LongToString(number, 0x10L, (long)num2);

            if (((0L <= number) && (num2 < str.Length)) && CalcHelper.ArgumentExists(args, 1))
            {
                return(CalcErrors.Number);
            }
            return(str);
        }