Reinterpret 64-bit signed integer to a double-precision floating point number in C#

The BitConverter.Int64BitsToDouble() method in C# reinterprets the bit pattern of a 64-bit signed integer as a double-precision floating point number. This is not a numeric conversion − it treats the integer's binary representation as if it were the IEEE 754 double format.

Syntax

Following is the syntax for the Int64BitsToDouble method −

public static double Int64BitsToDouble(long value)

Parameters

  • value − A 64-bit signed integer whose bit pattern will be reinterpreted as a double.

Return Value

Returns a double-precision floating point number whose bit representation is equivalent to the input long value.

Bit Reinterpretation Process long (64 bits) 01000000 00010100... double (64 bits) Same bit pattern Reinterpret No numeric conversion - just bit pattern reinterpretation

Using Int64BitsToDouble with Small Values

Example

using System;
public class Demo {
   public static void Main() {
      long d = 20;
      Console.WriteLine("Value (64-bit signed integer) = " + d);
      double res = BitConverter.Int64BitsToDouble(d);
      Console.WriteLine("Value (double-precision floating point number) = " + res);
      Console.WriteLine("Scientific notation: " + res.ToString("E"));
   }
}

The output of the above code is −

Value (64-bit signed integer) = 20
Value (double-precision floating point number) = 9.88131291682493E-323
Scientific notation: 9.881313E-323

Using Int64BitsToDouble with Larger Values

Example

using System;
public class Demo {
   public static void Main() {
      long d = 9846587687;
      Console.WriteLine("Value (64-bit signed integer) = " + d);
      double res = BitConverter.Int64BitsToDouble(d);
      Console.WriteLine("Value (double-precision floating point number) = " + res);
      
      // Show hex representation for clarity
      Console.WriteLine("Hex representation of long: 0x" + d.ToString("X"));
      Console.WriteLine("Hex representation of double bits: 0x" + 
                       BitConverter.DoubleToInt64Bits(res).ToString("X"));
   }
}

The output of the above code is −

Value (64-bit signed integer) = 9846587687
Value (double-precision floating point number) = 4.86486070491012E-314
Hex representation of long: 0x24B1F3927
Hex representation of double bits: 0x24B1F3927

Round-trip Conversion Example

Example

using System;
public class Demo {
   public static void Main() {
      double original = 3.14159;
      Console.WriteLine("Original double: " + original);
      
      // Convert double to long bits
      long bits = BitConverter.DoubleToInt64Bits(original);
      Console.WriteLine("As long bits: " + bits);
      
      // Convert back to double
      double restored = BitConverter.Int64BitsToDouble(bits);
      Console.WriteLine("Restored double: " + restored);
      Console.WriteLine("Values equal: " + (original == restored));
   }
}

The output of the above code is −

Original double: 3.14159
As long bits: 4614256447914709615
Restored double: 3.14159
Values equal: True

Common Use Cases

  • Binary serialization − Converting floating point values to integer format for storage or transmission.

  • Low-level data manipulation − Working with the actual bit representation of floating point numbers.

  • Reverse engineering − Analyzing binary data that contains encoded double values.

  • Round-trip operations − Used with DoubleToInt64Bits for preserving exact bit patterns.

Conclusion

The BitConverter.Int64BitsToDouble() method performs bit-level reinterpretation, not numeric conversion. It treats the 64-bit integer's binary pattern as IEEE 754 double format, making it useful for low-level data operations and binary serialization scenarios.

Updated on: 2026-03-17T07:04:36+05:30

563 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements