Export (0) Print
Expand All

BitConverter.DoubleToInt64Bits Method

Converts the specified double-precision floating point number to a 64-bit signed integer.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static long DoubleToInt64Bits (
	double value
)
public static long DoubleToInt64Bits (
	double value
)
public static function DoubleToInt64Bits (
	value : double
) : long

Parameters

value

The number to convert.

Return Value

A 64-bit signed integer whose value is equivalent to value.

The following code example converts the bit patterns of several Double values to Int64 values with the DoubleToInt64Bits method.

// Example of the BitConverter.DoubleToInt64Bits method.
using System;

class DoubleToInt64BitsDemo
{
    const string formatter = "{0,25:E16}{1,23:X16}";
 
    // Reinterpret the double argument as a long.
    public static void DoubleToLongBits( double argument )
    {
        long longValue;
        longValue = BitConverter.DoubleToInt64Bits( argument );

        // Display the resulting long in hexadecimal.
        Console.WriteLine( formatter, argument, longValue );
    }
       
    public static void Main( )
    {
        Console.WriteLine( 
            "This example of the BitConverter.DoubleToInt64Bits( " +
            "double ) \nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "double argument", 
            "hexadecimal value" );
        Console.WriteLine( formatter, "---------------", 
            "-----------------" );
          
        // Convert double values and display the results.
        DoubleToLongBits( 1.0 );
        DoubleToLongBits( 15.0 );
        DoubleToLongBits( 255.0 );
        DoubleToLongBits( 4294967295.0 );
        DoubleToLongBits( 0.00390625 );
        DoubleToLongBits( 0.00000000023283064365386962890625 );
        DoubleToLongBits( 1.234567890123E-300 );
        DoubleToLongBits( 1.23456789012345E-150 );
        DoubleToLongBits( 1.2345678901234565 );
        DoubleToLongBits( 1.2345678901234567 );
        DoubleToLongBits( 1.2345678901234569 );
        DoubleToLongBits( 1.23456789012345678E+150 );
        DoubleToLongBits( 1.234567890123456789E+300 );
        DoubleToLongBits( double.MinValue );
        DoubleToLongBits( double.MaxValue );
        DoubleToLongBits( double.Epsilon );
        DoubleToLongBits( double.NaN );
        DoubleToLongBits( double.NegativeInfinity );
        DoubleToLongBits( double.PositiveInfinity );
    }
}

/*
This example of the BitConverter.DoubleToInt64Bits( double )
method generates the following output.

          double argument      hexadecimal value
          ---------------      -----------------
  1.0000000000000000E+000       3FF0000000000000
  1.5000000000000000E+001       402E000000000000
  2.5500000000000000E+002       406FE00000000000
  4.2949672950000000E+009       41EFFFFFFFE00000
  3.9062500000000000E-003       3F70000000000000
  2.3283064365386963E-010       3DF0000000000000
  1.2345678901230000E-300       01AA74FE1C1E7E45
  1.2345678901234500E-150       20D02A36586DB4BB
  1.2345678901234565E+000       3FF3C0CA428C59FA
  1.2345678901234567E+000       3FF3C0CA428C59FB
  1.2345678901234569E+000       3FF3C0CA428C59FC
  1.2345678901234569E+150       5F182344CD3CDF9F
  1.2345678901234569E+300       7E3D7EE8BCBBD352
 -1.7976931348623157E+308       FFEFFFFFFFFFFFFF
  1.7976931348623157E+308       7FEFFFFFFFFFFFFF
  4.9406564584124654E-324       0000000000000001
                      NaN       FFF8000000000000
                -Infinity       FFF0000000000000
                 Infinity       7FF0000000000000
*/

// Example of the BitConverter.DoubleToInt64Bits method.
import System.*;

class DoubleToInt64BitsDemo
{
    private static String formatter = "{0,25:E16}{1,23:X16}";

    // Reinterpret the double argument as a long.
    public static void DoubleToLongBits(double argument)
    {
        long longValue;
        longValue = BitConverter.DoubleToInt64Bits(argument);

        // Display the resulting long in hexadecimal.
        Console.WriteLine(formatter, (System.Double)(argument), 
            (Int64)longValue);
    } //DoubleToLongBits

    public static void main(String[] args)
    {
        Console.WriteLine("This example of the "
            + "BitConverter.DoubleToInt64Bits( double )\n"
            + "method generates the following output.\n");
        Console.WriteLine(formatter, "double argument", "hexadecimal value");
        Console.WriteLine(formatter, "---------------", "-----------------");

        // Convert double values and display the results.
        DoubleToLongBits(1.0);
        DoubleToLongBits(15.0);
        DoubleToLongBits(255.0);
        DoubleToLongBits(4294967295.0);
        DoubleToLongBits(0.00390625);
        DoubleToLongBits(0.00000000023283064365386962890625);
        DoubleToLongBits(1.234567890123E-300);
        DoubleToLongBits(1.23456789012345E-150);
        DoubleToLongBits(1.2345678901234565);
        DoubleToLongBits(1.2345678901234567);
        DoubleToLongBits(1.2345678901234569);
        DoubleToLongBits(1.23456789012345678E+150);
        DoubleToLongBits(1.234567890123456789E+300);
        DoubleToLongBits(System.Double.MinValue);
        DoubleToLongBits(System.Double.MaxValue);
        DoubleToLongBits(System.Double.Epsilon);
        DoubleToLongBits(System.Double.NaN);
        DoubleToLongBits(System.Double.NegativeInfinity);
        DoubleToLongBits(System.Double.PositiveInfinity);
    } //main
} //DoubleToInt64BitsDemo
/*
This example of the BitConverter.DoubleToInt64Bits( double )
method generates the following output.

          double argument      hexadecimal value
          ---------------      -----------------
  1.0000000000000000E+000       3FF0000000000000
  1.5000000000000000E+001       402E000000000000
  2.5500000000000000E+002       406FE00000000000
  4.2949672950000000E+009       41EFFFFFFFE00000
  3.9062500000000000E-003       3F70000000000000
  2.3283064365386963E-010       3DF0000000000000
  1.2345678901230000E-300       01AA74FE1C1E7E45
  1.2345678901234500E-150       20D02A36586DB4BB
  1.2345678901234565E+000       3FF3C0CA428C59FA
  1.2345678901234567E+000       3FF3C0CA428C59FB
  1.2345678901234569E+000       3FF3C0CA428C59FC
  1.2345678901234569E+150       5F182344CD3CDF9F
  1.2345678901234569E+300       7E3D7EE8BCBBD352
 -1.7976931348623157E+308       FFEFFFFFFFFFFFFF
  1.7976931348623157E+308       7FEFFFFFFFFFFFFF
  4.9406564584124654E-324       0000000000000001
                      NaN       FFF8000000000000
                -Infinity       FFF0000000000000
                 Infinity       7FF0000000000000

*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft