BitConverter.Int64BitsToDouble() Method in C#

The BitConverter.Int64BitsToDouble() method in C# is used to reinterpret the specified 64-bit signed integer to a double-precision floating-point number. This method performs a bit-level reinterpretation rather than a numeric conversion, meaning it treats the long integer's binary representation as if it were the binary representation of a double.

Syntax

Following is the syntax −

public static double Int64BitsToDouble(long value);

Parameters

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

Return Value

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

How It Works

The method performs a direct binary reinterpretation without any mathematical conversion. The 64 bits of the long integer are treated as the IEEE 754 double-precision format consisting of 1 sign bit, 11 exponent bits, and 52 mantissa bits.

64-bit Long to Double Conversion S Exponent (11 bits) Mantissa (52 bits) Sign Power of 2 Fractional Part Same 64 bits, different interpretation

Example with Small Values

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

Example with Larger Values

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 binary representation
        Console.WriteLine("Binary representation of long: " + Convert.ToString(d, 2).PadLeft(64, '0'));
    }
}

The output of the above code is −

Value (64-bit signed integer) = 9846587687
Value (double-precision floating point number) = 4.86486070491012E-314
Binary representation of long: 0000000000000000000000000000000000000010010100111011110110100111

Practical Example with Known Double Value

using System;

public class Demo {
    public static void Main() {
        // First convert a known double to long bits
        double originalDouble = 123.456;
        long bits = BitConverter.DoubleToInt64Bits(originalDouble);
        Console.WriteLine("Original double: " + originalDouble);
        Console.WriteLine("As long bits: " + bits);
        
        // Now convert back using Int64BitsToDouble
        double convertedBack = BitConverter.Int64BitsToDouble(bits);
        Console.WriteLine("Converted back to double: " + convertedBack);
        Console.WriteLine("Are they equal? " + (originalDouble == convertedBack));
    }
}

The output of the above code is −

Original double: 123.456
As long bits: 4638387860618067575
Converted back to double: 123.456
Are they equal? True

Common Use Cases

  • Binary serialization − When you need to store double values as integer types in databases or files.

  • Low-level programming − Direct manipulation of floating-point bit patterns for performance-critical applications.

  • Network protocols − Converting between different data representations while maintaining exact bit patterns.

Conclusion

The BitConverter.Int64BitsToDouble() method performs bit-level reinterpretation of a 64-bit integer as a double-precision floating-point number. This method is essential for low-level operations where you need to manipulate the exact binary representation of floating-point numbers without performing mathematical conversions.

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

133 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements