/// <summary>
        /// Binaries the representation.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <returns></returns>
        public static string IEEE754Format(this double number)
        {
            var dl = new DoubleToLongExplorer();

            dl.D = number;

            long longNumber = dl.L;
            bool negative   = (longNumber < 0);
            int  exponent   = (int)((longNumber >> 52) & 0x7ffL);
            long mantissa   = longNumber & 0xfffffffffffffL;

            string s = ((negative) ? 1 : 0).ToString();

            s += GetExponent(exponent);
            s += GetMantissa(mantissa);

            return(s);
        }
Beispiel #2
0
        /// <summary>
        /// Binaries the representation.
        /// </summary>
        /// <param name="number">The number.</param>
        /// <returns></returns>
        public static string IEEE754Format(this double number)
        {
            var dl = new DoubleToLongExplorer();

            dl.D = number;

            long longNumber = dl.L;

            int bitsCount = sizeof(double) * 8;

            char[] result = new char[bitsCount];
            result[0] = (longNumber < 0) ? '1' : '0';

            for (int i = bitsCount - 2, j = 1; i >= 0; i--, j++)
            {
                result[j] = (longNumber & (1L << i)) != 0 ? '1' : '0';
            }

            return(new string(result));
        }