C# | BitConverter.DoubleToInt64Bits() Method

BitConverter.DoubleToInt64Bits(Double) Method is used to convert the specified double-precision floating point number to a 64-bit signed integer.

Syntax:

public static long DoubleToInt64Bits (double value);

Here, the value is the number which is to be converted.

Return Value: This method returns a 64-bit signed integer whose value is equivalent to value.

Below programs illustrate the use of BitConverter.DoubleToInt64Bits(Double) Method:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate
// BitConverter.DoubleToInt64Bits()
// Method
using System;
  
public class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // declaring and initializing double value
        double value = 1.2345678901234565;
  
        // Display the double value
        Console.Write("double-precision floating point: ");
        Console.WriteLine("{0}", value);
        Console.WriteLine();
  
        // Converting double to long value
        // using BitConverter.DoubleToInt64Bits()
        // Method
        long value1 = BitConverter.DoubleToInt64Bits(value);
  
        // Display the 64-bit signed integer.
        Console.Write("64-bit signed integer: ");
        Console.WriteLine("{0}", value1);
    }
}

chevron_right


Output:

double-precision floating point: 1.23456789012346

64-bit signed integer: 4608238818662570490

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to demonstrate
// BitConverter.DoubleToInt64Bits()
// Method
using System;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // declaring and initializing double value
        double value = 1.0;
  
        // Display the double value
        Console.Write("double-precision floating point: ");
        Console.WriteLine("{0}", value);
        Console.WriteLine();
  
        // Converting double to long value
        // using BitConverter.DoubleToInt64Bits()
        // Method
        long value1 = BitConverter.DoubleToInt64Bits(value);
  
        // Display the 64-bit signed integer.
        Console.Write("64-bit signed integer: ");
        Console.WriteLine("{0}", value1);
        Console.WriteLine();
  
        // Display the Hexadecimal value
        Console.Write("Hexadecimal value: ");
        Console.WriteLine(value1.ToString("X"));
    }
}

chevron_right


Output:

double-precision floating point: 1

64-bit signed integer: 4607182418800017408

Hexadecimal value: 3FF0000000000000

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.