Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
System
BitConverter Class
GetBytes Method
 GetBytes Method (Double)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
BitConverter..::.GetBytes Method (Double)

Returns the specified double-precision floating point value as an array of bytes.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
Public Shared Function GetBytes ( _
    value As Double _
) As Byte()
C#
public static byte[] GetBytes(
    double value
)
Visual C++
public:
static array<unsigned char>^ GetBytes(
    double value
)
F#
static member GetBytes : 
        value:float -> byte[] 

Parameters

value
Type: System..::.Double
The number to convert.

Return Value

Type: array<System..::.Byte>[]()[]
An array of bytes with length 8.

The following code example converts the bit patterns of Double values to Byte arrays with the GetBytes method.

Visual Basic
' Example of the BitConverter.GetBytes( Double ) method.
Imports System
Imports Microsoft.VisualBasic

Module GetBytesDoubleDemo

    Const formatter As String = "{0,25:E16}{1,30}"

    ' Convert a Double argument to a Byte array and display it.
    Sub GetBytesDouble( argument As Double )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub 

    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( Double ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Double", "Byte array" )
        Console.WriteLine( formatter, "------", "----------" )

        ' Convert Double values and display the results.
        GetBytesDouble( 0.0 )
        GetBytesDouble( 1.0 )
        GetBytesDouble( 255.0 )
        GetBytesDouble( 4294967295.0 )
        GetBytesDouble( 0.00390625 )
        GetBytesDouble( 0.00000000023283064365386962890625 )
        GetBytesDouble( 1.23456789012345E-300 )
        GetBytesDouble( 1.2345678901234565 )
        GetBytesDouble( 1.2345678901234567 )
        GetBytesDouble( 1.2345678901234569 )
        GetBytesDouble( 1.23456789012345678E+300 )
        GetBytesDouble( Double.MinValue )
        GetBytesDouble( Double.MaxValue )
        GetBytesDouble( Double.Epsilon )
        GetBytesDouble( Double.NaN )
        GetBytesDouble( Double.NegativeInfinity )
        GetBytesDouble( Double.PositiveInfinity )
    End Sub 
End Module

' This example of the BitConverter.GetBytes( Double )
' method generates the following output.
' 
'                    Double                    Byte array
'                    ------                    ----------
'   0.0000000000000000E+000       00-00-00-00-00-00-00-00
'   1.0000000000000000E+000       00-00-00-00-00-00-F0-3F
'   2.5500000000000000E+002       00-00-00-00-00-E0-6F-40
'   4.2949672950000000E+009       00-00-E0-FF-FF-FF-EF-41
'   3.9062500000000000E-003       00-00-00-00-00-00-70-3F
'   2.3283064365386963E-010       00-00-00-00-00-00-F0-3D
'   1.2345678901234500E-300       DF-88-1E-1C-FE-74-AA-01
'   1.2345678901234565E+000       FA-59-8C-42-CA-C0-F3-3F
'   1.2345678901234567E+000       FB-59-8C-42-CA-C0-F3-3F
'   1.2345678901234569E+000       FC-59-8C-42-CA-C0-F3-3F
'   1.2345678901234569E+300       52-D3-BB-BC-E8-7E-3D-7E
'  -1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-FF
'   1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-7F
'   4.9406564584124654E-324       01-00-00-00-00-00-00-00
'                       NaN       00-00-00-00-00-00-F8-FF
'                 -Infinity       00-00-00-00-00-00-F0-FF
'                  Infinity       00-00-00-00-00-00-F0-7F
C#
// Example of the BitConverter.GetBytes( double ) method.
using System;

class GetBytesDoubleDemo
{
    const string formatter = "{0,25:E16}{1,30}";

    // Convert a double argument to a byte array and display it.
    public static void GetBytesDouble( double argument )
    {
        byte[ ] byteArray = BitConverter.GetBytes( argument );
        Console.WriteLine( formatter, argument, 
            BitConverter.ToString( byteArray ) );
    }

    public static void Main( )
    {
        Console.WriteLine( 
            "This example of the BitConverter.GetBytes( double ) " +
            "\nmethod generates the following output.\n" );
        Console.WriteLine( formatter, "double", "byte array" );
        Console.WriteLine( formatter, "------", "----------" );

        // Convert double values and display the results.
        GetBytesDouble( 0.0 );
        GetBytesDouble( 1.0 );
        GetBytesDouble( 255.0 );
        GetBytesDouble( 4294967295.0 );
        GetBytesDouble( 0.00390625 );
        GetBytesDouble( 0.00000000023283064365386962890625 );
        GetBytesDouble( 1.23456789012345E-300 );
        GetBytesDouble( 1.2345678901234565 );
        GetBytesDouble( 1.2345678901234567 );
        GetBytesDouble( 1.2345678901234569 );
        GetBytesDouble( 1.23456789012345678E+300 );
        GetBytesDouble( double.MinValue );
        GetBytesDouble( double.MaxValue );
        GetBytesDouble( double.Epsilon );
        GetBytesDouble( double.NaN );
        GetBytesDouble( double.NegativeInfinity );
        GetBytesDouble( double.PositiveInfinity );
    }
}

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

                   double                    byte array
                   ------                    ----------
  0.0000000000000000E+000       00-00-00-00-00-00-00-00
  1.0000000000000000E+000       00-00-00-00-00-00-F0-3F
  2.5500000000000000E+002       00-00-00-00-00-E0-6F-40
  4.2949672950000000E+009       00-00-E0-FF-FF-FF-EF-41
  3.9062500000000000E-003       00-00-00-00-00-00-70-3F
  2.3283064365386963E-010       00-00-00-00-00-00-F0-3D
  1.2345678901234500E-300       DF-88-1E-1C-FE-74-AA-01
  1.2345678901234565E+000       FA-59-8C-42-CA-C0-F3-3F
  1.2345678901234567E+000       FB-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+000       FC-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+300       52-D3-BB-BC-E8-7E-3D-7E
 -1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-FF
  1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-7F
  4.9406564584124654E-324       01-00-00-00-00-00-00-00
                      NaN       00-00-00-00-00-00-F8-FF
                -Infinity       00-00-00-00-00-00-F0-FF
                 Infinity       00-00-00-00-00-00-F0-7F
*/
Visual C++
// Example of the BitConverter::GetBytes( double ) method.
using namespace System;

// Convert a double argument to a byte array and display it.
void GetBytesDouble( double argument )
{
   array<Byte>^byteArray = BitConverter::GetBytes( argument );
   Console::WriteLine( "{0,25:E16}{1,30}", argument, BitConverter::ToString( byteArray ) );
}

int main()
{
   Console::WriteLine( "This example of the BitConverter::GetBytes( double ) "
   "\nmethod generates the following output.\n" );
   Console::WriteLine( "{0,25:E16}{1,30}", "double", "byte array" );
   Console::WriteLine( "{0,25:E16}{1,30}", "------", "----------" );

   // Convert double values and display the results.
   GetBytesDouble( 0.0 );
   GetBytesDouble( 1.0 );
   GetBytesDouble( 255.0 );
   GetBytesDouble( 4294967295.0 );
   GetBytesDouble( 0.00390625 );
   GetBytesDouble( 0.00000000023283064365386962890625 );
   GetBytesDouble( 1.23456789012345E-300 );
   GetBytesDouble( 1.2345678901234565 );
   GetBytesDouble( 1.2345678901234567 );
   GetBytesDouble( 1.2345678901234569 );
   GetBytesDouble( 1.23456789012345678E+300 );
   GetBytesDouble( Double::MinValue );
   GetBytesDouble( Double::MaxValue );
   GetBytesDouble( Double::Epsilon );
   GetBytesDouble( Double::NaN );
   GetBytesDouble( Double::NegativeInfinity );
   GetBytesDouble( Double::PositiveInfinity );
}

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

                   double                    byte array
                   ------                    ----------
  0.0000000000000000E+000       00-00-00-00-00-00-00-00
  1.0000000000000000E+000       00-00-00-00-00-00-F0-3F
  2.5500000000000000E+002       00-00-00-00-00-E0-6F-40
  4.2949672950000000E+009       00-00-E0-FF-FF-FF-EF-41
  3.9062500000000000E-003       00-00-00-00-00-00-70-3F
  2.3283064365386963E-010       00-00-00-00-00-00-F0-3D
  1.2345678901234500E-300       DF-88-1E-1C-FE-74-AA-01
  1.2345678901234565E+000       FA-59-8C-42-CA-C0-F3-3F
  1.2345678901234567E+000       FB-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+000       FC-59-8C-42-CA-C0-F3-3F
  1.2345678901234569E+300       52-D3-BB-BC-E8-7E-3D-7E
 -1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-FF
  1.7976931348623157E+308       FF-FF-FF-FF-FF-FF-EF-7F
  4.9406564584124654E-324       01-00-00-00-00-00-00-00
                      NaN       00-00-00-00-00-00-F8-FF
                -Infinity       00-00-00-00-00-00-F0-FF
                 Infinity       00-00-00-00-00-00-F0-7F
*/

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker