다음을 통해 공유


BitConverter.ToDouble 메서드

정의

오버로드

ToDouble(ReadOnlySpan<Byte>)

읽기 전용 바이트 범위를 배정밀도 부동 소수점 값으로 변환합니다.

ToDouble(Byte[], Int32)

8바이트에서 변환된 배정밀도 부동 소수점 숫자를 바이트 배열의 지정된 위치에 반환합니다.

ToDouble(ReadOnlySpan<Byte>)

읽기 전용 바이트 범위를 배정밀도 부동 소수점 값으로 변환합니다.

public:
 static double ToDouble(ReadOnlySpan<System::Byte> value);
public static double ToDouble (ReadOnlySpan<byte> value);
static member ToDouble : ReadOnlySpan<byte> -> double
Public Shared Function ToDouble (value As ReadOnlySpan(Of Byte)) As Double

매개 변수

value
ReadOnlySpan<Byte>

변환할 바이트를 포함하는 읽기 전용 범위입니다.

반환

Double

변환된 바이트를 나타내는 배정밀도 부동 소수점 값입니다.

예외

value의 길이가 Double 값의 길이보다 작습니다.

적용 대상

ToDouble(Byte[], Int32)

8바이트에서 변환된 배정밀도 부동 소수점 숫자를 바이트 배열의 지정된 위치에 반환합니다.

public:
 static double ToDouble(cli::array <System::Byte> ^ value, int startIndex);
public static double ToDouble (byte[] value, int startIndex);
static member ToDouble : byte[] * int -> double
Public Shared Function ToDouble (value As Byte(), startIndex As Integer) As Double

매개 변수

value
Byte[]

변환할 8바이트를 포함하는 바이트 배열입니다.

startIndex
Int32

value 내의 시작 위치입니다.

반환

Double

8바이트로 구성된 배정밀도 부동 소수점 숫자입니다 startIndex.

예외

startIndexvalue의 길이에서 7을 뺀 값보다 크거나 같고 value의 길이에서 1을 뺀 값보다 작거나 같은 경우

value이(가) null인 경우

startIndex가 0보다 작거나 value - 1의 길이보다 큰 경우

예제

다음 코드 예제에서는 배열의 Byte 요소를 메서드를 사용하여 Double 값으로 ToDouble 변환합니다.

// Example of the BitConverter::ToDouble method.
using namespace System;

// Convert eight byte array elements to a double and display it.
void BAToDouble( array<unsigned char>^bytes, int index )
{
   double value = BitConverter::ToDouble( bytes, index );
   Console::WriteLine( "{0,5}{1,27}{2,27:E16}", index, BitConverter::ToString( bytes, index, 8 ), value );
}


// Display a byte array, using multiple lines if necessary.
void WriteMultiLineByteArray( array<unsigned char>^bytes )
{
   const int rowSize = 20;
   int iter;
   Console::WriteLine( "initial unsigned char array" );
   Console::WriteLine( "---------------------------" );
   for ( iter = 0; iter < bytes->Length - rowSize; iter += rowSize )
   {
      Console::Write( BitConverter::ToString( bytes, iter, rowSize ) );
      Console::WriteLine( "-" );

   }
   Console::WriteLine( BitConverter::ToString( bytes, iter ) );
   Console::WriteLine();
}

int main()
{
   array<unsigned char>^byteArray = {0,0,0,0,0,0,0,0,240,63,0,0,0,0,0,224,111,64,0,0,224,255,255,255,239,65,0,0,0,0,0,0,112,63,0,0,0,0,0,0,240,61,223,136,30,28,254,116,170,1,250,89,140,66,202,192,243,63,251,89,140,66,202,192,243,63,252,89,140,66,202,192,243,63,82,211,187,188,232,126,61,126,255,255,255,255,255,255,239,255,255,255,255,255,255,239,127,1,0,0,0,0,0,0,0,248,255,0,0,0,0,0,0,240,255,0,0,0,0,0,0,240,127};
   Console::WriteLine( "This example of the BitConverter::ToDouble( unsigned "
   "char[ ], int ) \nmethod generates the following output. It "
   "converts elements of a \nbyte array to double values.\n" );
   WriteMultiLineByteArray( byteArray );
   Console::WriteLine( "{0,5}{1,27}{2,27:E16}", "index", "array elements", "double" );
   Console::WriteLine( "{0,5}{1,27}{2,27:E16}", "-----", "--------------", "------" );
   
   // Convert byte array elements to double values.
   BAToDouble( byteArray, 0 );
   BAToDouble( byteArray, 2 );
   BAToDouble( byteArray, 10 );
   BAToDouble( byteArray, 18 );
   BAToDouble( byteArray, 26 );
   BAToDouble( byteArray, 34 );
   BAToDouble( byteArray, 42 );
   BAToDouble( byteArray, 50 );
   BAToDouble( byteArray, 58 );
   BAToDouble( byteArray, 66 );
   BAToDouble( byteArray, 74 );
   BAToDouble( byteArray, 82 );
   BAToDouble( byteArray, 89 );
   BAToDouble( byteArray, 97 );
   BAToDouble( byteArray, 99 );
   BAToDouble( byteArray, 107 );
   BAToDouble( byteArray, 115 );
}

/*
This example of the BitConverter.ToDouble( byte( ), int )
method generates the following output. It converts elements
of a byte array to double values.

initial byte array
------------------
00-00-00-00-00-00-00-00-F0-3F-00-00-00-00-00-E0-6F-40-00-00-
E0-FF-FF-FF-EF-41-00-00-00-00-00-00-70-3F-00-00-00-00-00-00-
F0-3D-DF-88-1E-1C-FE-74-AA-01-FA-59-8C-42-CA-C0-F3-3F-FB-59-
8C-42-CA-C0-F3-3F-FC-59-8C-42-CA-C0-F3-3F-52-D3-BB-BC-E8-7E-
3D-7E-FF-FF-FF-FF-FF-FF-EF-FF-FF-FF-FF-FF-FF-EF-7F-01-00-00-
00-00-00-00-00-F8-FF-00-00-00-00-00-00-F0-FF-00-00-00-00-00-
00-F0-7F

index             array elements                     double
-----             --------------                     ------
    0    00-00-00-00-00-00-00-00    0.0000000000000000E+000
    2    00-00-00-00-00-00-F0-3F    1.0000000000000000E+000
   10    00-00-00-00-00-E0-6F-40    2.5500000000000000E+002
   18    00-00-E0-FF-FF-FF-EF-41    4.2949672950000000E+009
   26    00-00-00-00-00-00-70-3F    3.9062500000000000E-003
   34    00-00-00-00-00-00-F0-3D    2.3283064365386963E-010
   42    DF-88-1E-1C-FE-74-AA-01    1.2345678901234500E-300
   50    FA-59-8C-42-CA-C0-F3-3F    1.2345678901234565E+000
   58    FB-59-8C-42-CA-C0-F3-3F    1.2345678901234567E+000
   66    FC-59-8C-42-CA-C0-F3-3F    1.2345678901234569E+000
   74    52-D3-BB-BC-E8-7E-3D-7E    1.2345678901234569E+300
   82    FF-FF-FF-FF-FF-FF-EF-FF   -1.7976931348623157E+308
   89    FF-FF-FF-FF-FF-FF-EF-7F    1.7976931348623157E+308
   97    01-00-00-00-00-00-00-00    4.9406564584124654E-324
   99    00-00-00-00-00-00-F8-FF                        NaN
  107    00-00-00-00-00-00-F0-FF                  -Infinity
  115    00-00-00-00-00-00-F0-7F                   Infinity
*/
// Example of the BitConverter.ToDouble method.
using System;

class BytesToDoubleDemo
{
    const string formatter = "{0,5}{1,27}{2,27:E16}";

    // Convert eight byte array elements to a double and display it.
    public static void BAToDouble( byte[ ] bytes, int index )
    {
        double value = BitConverter.ToDouble( bytes, index );

        Console.WriteLine( formatter, index,
            BitConverter.ToString( bytes, index, 8 ), value );
    }

    // Display a byte array, using multiple lines if necessary.
    public static void WriteMultiLineByteArray( byte[ ] bytes )
    {
        const int rowSize = 20;
        int iter;

        Console.WriteLine( "initial byte array" );
        Console.WriteLine( "------------------" );

        for( iter = 0; iter < bytes.Length - rowSize; iter += rowSize )
        {
            Console.Write(
                BitConverter.ToString( bytes, iter, rowSize ) );
            Console.WriteLine( "-" );
        }

        Console.WriteLine( BitConverter.ToString( bytes, iter ) );
        Console.WriteLine( );
    }

    public static void Main( )
    {
        byte[ ] byteArray = {
              0,   0,   0,   0,   0,   0,   0,   0, 240,  63,
              0,   0,   0,   0,   0, 224, 111,  64,   0,   0,
            224, 255, 255, 255, 239,  65,   0,   0,   0,   0,
              0,   0, 112,  63,   0,   0,   0,   0,   0,   0,
            240,  61, 223, 136,  30,  28, 254, 116, 170,   1,
            250,  89, 140,  66, 202, 192, 243,  63, 251,  89,
            140,  66, 202, 192, 243,  63, 252,  89, 140,  66,
            202, 192, 243,  63,  82, 211, 187, 188, 232, 126,
             61, 126, 255, 255, 255, 255, 255, 255, 239, 255,
            255, 255, 255, 255, 255, 239, 127,   1,   0,   0,
              0,   0,   0,   0,   0, 248, 255,   0,   0,   0,
              0,   0,   0, 240, 255,   0,   0,   0,   0,   0,
              0, 240, 127 };

        Console.WriteLine(
            "This example of the BitConverter.ToDouble( byte[ ], " +
            "int ) \nmethod generates the following output. It " +
            "converts elements \nof a byte array to double values.\n" );

        WriteMultiLineByteArray( byteArray );

        Console.WriteLine( formatter, "index", "array elements",
            "double" );
        Console.WriteLine( formatter, "-----", "--------------",
            "------" );

        // Convert byte array elements to double values.
        BAToDouble( byteArray, 0 );
        BAToDouble( byteArray, 2 );
        BAToDouble( byteArray, 10 );
        BAToDouble( byteArray, 18 );
        BAToDouble( byteArray, 26 );
        BAToDouble( byteArray, 34 );
        BAToDouble( byteArray, 42 );
        BAToDouble( byteArray, 50 );
        BAToDouble( byteArray, 58 );
        BAToDouble( byteArray, 66 );
        BAToDouble( byteArray, 74 );
        BAToDouble( byteArray, 82 );
        BAToDouble( byteArray, 89 );
        BAToDouble( byteArray, 97 );
        BAToDouble( byteArray, 99 );
        BAToDouble( byteArray, 107 );
        BAToDouble( byteArray, 115 );
    }
}

/*
This example of the BitConverter.ToDouble( byte[ ], int )
method generates the following output. It converts elements
of a byte array to double values.

initial byte array
------------------
00-00-00-00-00-00-00-00-F0-3F-00-00-00-00-00-E0-6F-40-00-00-
E0-FF-FF-FF-EF-41-00-00-00-00-00-00-70-3F-00-00-00-00-00-00-
F0-3D-DF-88-1E-1C-FE-74-AA-01-FA-59-8C-42-CA-C0-F3-3F-FB-59-
8C-42-CA-C0-F3-3F-FC-59-8C-42-CA-C0-F3-3F-52-D3-BB-BC-E8-7E-
3D-7E-FF-FF-FF-FF-FF-FF-EF-FF-FF-FF-FF-FF-FF-EF-7F-01-00-00-
00-00-00-00-00-F8-FF-00-00-00-00-00-00-F0-FF-00-00-00-00-00-
00-F0-7F

index             array elements                     double
-----             --------------                     ------
    0    00-00-00-00-00-00-00-00    0.0000000000000000E+000
    2    00-00-00-00-00-00-F0-3F    1.0000000000000000E+000
   10    00-00-00-00-00-E0-6F-40    2.5500000000000000E+002
   18    00-00-E0-FF-FF-FF-EF-41    4.2949672950000000E+009
   26    00-00-00-00-00-00-70-3F    3.9062500000000000E-003
   34    00-00-00-00-00-00-F0-3D    2.3283064365386963E-010
   42    DF-88-1E-1C-FE-74-AA-01    1.2345678901234500E-300
   50    FA-59-8C-42-CA-C0-F3-3F    1.2345678901234565E+000
   58    FB-59-8C-42-CA-C0-F3-3F    1.2345678901234567E+000
   66    FC-59-8C-42-CA-C0-F3-3F    1.2345678901234569E+000
   74    52-D3-BB-BC-E8-7E-3D-7E    1.2345678901234569E+300
   82    FF-FF-FF-FF-FF-FF-EF-FF   -1.7976931348623157E+308
   89    FF-FF-FF-FF-FF-FF-EF-7F    1.7976931348623157E+308
   97    01-00-00-00-00-00-00-00    4.9406564584124654E-324
   99    00-00-00-00-00-00-F8-FF                        NaN
  107    00-00-00-00-00-00-F0-FF                  -Infinity
  115    00-00-00-00-00-00-F0-7F                   Infinity
*/
open System

let print obj1 obj2 obj3 = printfn $"{obj1,5}{obj2,27}{obj3,27:E16}"

// Convert eight byte array elements to a double and display it.
let BAToDouble bytes index =
    let value = BitConverter.ToDouble(bytes, index)

    print index (BitConverter.ToString(bytes, index, 8)) value

// Display a byte array, using multiple lines if necessary.
let writeMultiLineByteArray (bytes: byte []) =
    let rowSize = 20

    printfn "initial byte array"
    printfn "------------------"

    let mutable iter = 0
    for i in 0 .. rowSize .. (bytes.Length - rowSize - 1) do
        printfn $"{BitConverter.ToString(bytes, iter, rowSize)}-"
        iter <- i

    printfn $"{BitConverter.ToString(bytes, iter + rowSize)}\n"

let byteArray =
    [| 0uy; 0uy; 0uy; 0uy; 0uy; 0uy; 0uy; 0uy; 240uy; 63uy
       0uy; 0uy; 0uy; 0uy; 0uy; 224uy; 111uy; 64uy; 0uy; 0uy;
       224uy; 255uy; 255uy; 255uy; 239uy; 65uy; 0uy; 0uy; 0uy; 0uy
       0uy; 0uy; 112uy; 63uy; 0uy; 0uy; 0uy; 0uy; 0uy; 0uy
       240uy; 61uy; 223uy; 136uy; 30uy; 28uy; 254uy; 116uy; 170uy; 1uy
       250uy; 89uy; 140uy; 66uy; 202uy; 192uy; 243uy; 63uy; 251uy; 89uy
       140uy; 66uy; 202uy; 192uy; 243uy; 63uy; 252uy; 89uy; 140uy; 66uy
       202uy; 192uy; 243uy; 63uy; 82uy; 211uy; 187uy; 188uy; 232uy; 126uy
       61uy; 126uy; 255uy; 255uy; 255uy; 255uy; 255uy; 255uy; 239uy; 255uy
       255uy; 255uy; 255uy; 255uy; 255uy; 239uy; 127uy; 1uy; 0uy; 0uy
       0uy; 0uy; 0uy; 0uy; 0uy; 248uy; 255uy; 0uy; 0uy; 0uy
       0uy; 0uy; 0uy; 240uy; 255uy; 0uy; 0uy; 0uy; 0uy; 0uy
       0uy; 240uy; 127uy |]

printfn "This example of the BitConverter.ToDouble(byte [], int) \nmethod generates the following output. It converts elements \nof a byte array to double values.\n"

writeMultiLineByteArray byteArray

print "index" "array elements" "double"
print "-----" "--------------" "------"

// Convert byte array elements to double values.
BAToDouble byteArray 0
BAToDouble byteArray 2
BAToDouble byteArray 10
BAToDouble byteArray 18
BAToDouble byteArray 26
BAToDouble byteArray 34
BAToDouble byteArray 42
BAToDouble byteArray 50
BAToDouble byteArray 58
BAToDouble byteArray 66
BAToDouble byteArray 74
BAToDouble byteArray 82
BAToDouble byteArray 89
BAToDouble byteArray 97
BAToDouble byteArray 99
BAToDouble byteArray 107
BAToDouble byteArray 115


// This example of the BitConverter.ToDouble(byte [], int )
// method generates the following output. It converts elements
// of a byte array to double values.

// initial byte array
// ------------------
// 00-00-00-00-00-00-00-00-F0-3F-00-00-00-00-00-E0-6F-40-00-00-
// 00-00-00-00-00-00-00-00-F0-3F-00-00-00-00-00-E0-6F-40-00-00-
// E0-FF-FF-FF-EF-41-00-00-00-00-00-00-70-3F-00-00-00-00-00-00-
// F0-3D-DF-88-1E-1C-FE-74-AA-01-FA-59-8C-42-CA-C0-F3-3F-FB-59-
// 8C-42-CA-C0-F3-3F-FC-59-8C-42-CA-C0-F3-3F-52-D3-BB-BC-E8-7E-
// 3D-7E-FF-FF-FF-FF-FF-FF-EF-FF-FF-FF-FF-FF-FF-EF-7F-01-00-00-
// 00-F0-7F
//
// index             array elements                     double
// -----             --------------                     ------
//     0    00-00-00-00-00-00-00-00    0.0000000000000000E+000
//     2    00-00-00-00-00-00-F0-3F    1.0000000000000000E+000
//    10    00-00-00-00-00-E0-6F-40    2.5500000000000000E+002
//    18    00-00-E0-FF-FF-FF-EF-41    4.2949672950000000E+009
//    26    00-00-00-00-00-00-70-3F    3.9062500000000000E-003
//    34    00-00-00-00-00-00-F0-3D    2.3283064365386963E-010
//    42    DF-88-1E-1C-FE-74-AA-01    1.2345678901234500E-300
//    50    FA-59-8C-42-CA-C0-F3-3F    1.2345678901234565E+000
//    58    FB-59-8C-42-CA-C0-F3-3F    1.2345678901234567E+000
//    66    FC-59-8C-42-CA-C0-F3-3F    1.2345678901234569E+000
//    74    52-D3-BB-BC-E8-7E-3D-7E    1.2345678901234569E+300
//    82    FF-FF-FF-FF-FF-FF-EF-FF   -1.7976931348623157E+308
//    89    FF-FF-FF-FF-FF-FF-EF-7F    1.7976931348623157E+308
//    97    01-00-00-00-00-00-00-00    4.9406564584124654E-324
//    99    00-00-00-00-00-00-F8-FF                        NaN
//   107    00-00-00-00-00-00-F0-FF                         -∞
//   115    00-00-00-00-00-00-F0-7F                          ∞
' Example of the BitConverter.ToDouble method.
Module BytesToDoubleDemo

    Const formatter As String = "{0,5}{1,27}{2,27:E16}"
 
    ' Convert eight Byte array elements to a Double and display it.
    Sub BAToDouble( bytes( ) As Byte, index As Integer )

        Dim value As Double = BitConverter.ToDouble( bytes, index )

        Console.WriteLine( formatter, index, _
            BitConverter.ToString( bytes, index, 8 ), value )
    End Sub 

    ' Display a Byte array, using multiple lines if necessary.
    Sub WriteMultiLineByteArray( bytes( ) As Byte )
       
        Const rowSize As Integer = 20 
        Dim iter As Integer

        Console.WriteLine( "initial Byte array" )
        Console.WriteLine( "------------------" )

        For iter = 0 To bytes.Length - rowSize - 1 Step rowSize
            Console.Write( _
                BitConverter.ToString( bytes, iter, rowSize ) )
            Console.WriteLine( "-" )
        Next iter

        Console.WriteLine( BitConverter.ToString( bytes, iter ) )
        Console.WriteLine( )
    End Sub

    Sub Main( )
        Dim byteArray as Byte( ) = { _
              0,   0,   0,   0,   0,   0,   0,   0, 240,  63, _
              0,   0,   0,   0,   0, 224, 111,  64,   0,   0, _
            224, 255, 255, 255, 239,  65,   0,   0,   0,   0, _
              0,   0, 112,  63,   0,   0,   0,   0,   0,   0, _
            240,  61, 223, 136,  30,  28, 254, 116, 170,   1, _
            250,  89, 140,  66, 202, 192, 243,  63, 251,  89, _
            140,  66, 202, 192, 243,  63, 252,  89, 140,  66, _
            202, 192, 243,  63,  82, 211, 187, 188, 232, 126, _
             61, 126, 255, 255, 255, 255, 255, 255, 239, 255, _
            255, 255, 255, 255, 255, 239, 127,   1,   0,   0, _
              0,   0,   0,   0,   0, 248, 255,   0,   0,   0, _
              0,   0,   0, 240, 255,   0,   0,   0,   0,   0, _
              0, 240, 127 }

        Console.WriteLine( _
            "This example of the BitConverter.ToDouble( Byte( ), " & _
            "Integer ) " & vbCrLf & "method generates the " & _
            "following output. It converts elements " & vbCrLf & _
            "of a Byte array to Double values." & vbCrLf )

        WriteMultiLineByteArray( byteArray )

        Console.WriteLine( formatter, "index", "array elements", _
            "Double" )
        Console.WriteLine( formatter, "-----", "--------------", _
            "------" )
          
        ' Convert Byte array elements to Double values.
        BAToDouble( byteArray, 0 )
        BAToDouble( byteArray, 2 )
        BAToDouble( byteArray, 10 )
        BAToDouble( byteArray, 18 )
        BAToDouble( byteArray, 26 )
        BAToDouble( byteArray, 34 )
        BAToDouble( byteArray, 42 )
        BAToDouble( byteArray, 50 )
        BAToDouble( byteArray, 58 )
        BAToDouble( byteArray, 66 )
        BAToDouble( byteArray, 74 )
        BAToDouble( byteArray, 82 )
        BAToDouble( byteArray, 89 )
        BAToDouble( byteArray, 97 )
        BAToDouble( byteArray, 99 )
        BAToDouble( byteArray, 107 )
        BAToDouble( byteArray, 115 )
    End Sub 
End Module

' This example of the BitConverter.ToDouble( Byte( ), Integer )
' method generates the following output. It converts elements
' of a Byte array to Double values.
' 
' initial Byte array
' ------------------
' 00-00-00-00-00-00-00-00-F0-3F-00-00-00-00-00-E0-6F-40-00-00-
' E0-FF-FF-FF-EF-41-00-00-00-00-00-00-70-3F-00-00-00-00-00-00-
' F0-3D-DF-88-1E-1C-FE-74-AA-01-FA-59-8C-42-CA-C0-F3-3F-FB-59-
' 8C-42-CA-C0-F3-3F-FC-59-8C-42-CA-C0-F3-3F-52-D3-BB-BC-E8-7E-
' 3D-7E-FF-FF-FF-FF-FF-FF-EF-FF-FF-FF-FF-FF-FF-EF-7F-01-00-00-
' 00-00-00-00-00-F8-FF-00-00-00-00-00-00-F0-FF-00-00-00-00-00-
' 00-F0-7F
' 
' index             array elements                     Double
' -----             --------------                     ------
'     0    00-00-00-00-00-00-00-00    0.0000000000000000E+000
'     2    00-00-00-00-00-00-F0-3F    1.0000000000000000E+000
'    10    00-00-00-00-00-E0-6F-40    2.5500000000000000E+002
'    18    00-00-E0-FF-FF-FF-EF-41    4.2949672950000000E+009
'    26    00-00-00-00-00-00-70-3F    3.9062500000000000E-003
'    34    00-00-00-00-00-00-F0-3D    2.3283064365386963E-010
'    42    DF-88-1E-1C-FE-74-AA-01    1.2345678901234500E-300
'    50    FA-59-8C-42-CA-C0-F3-3F    1.2345678901234565E+000
'    58    FB-59-8C-42-CA-C0-F3-3F    1.2345678901234567E+000
'    66    FC-59-8C-42-CA-C0-F3-3F    1.2345678901234569E+000
'    74    52-D3-BB-BC-E8-7E-3D-7E    1.2345678901234569E+300
'    82    FF-FF-FF-FF-FF-FF-EF-FF   -1.7976931348623157E+308
'    89    FF-FF-FF-FF-FF-FF-EF-7F    1.7976931348623157E+308
'    97    01-00-00-00-00-00-00-00    4.9406564584124654E-324
'    99    00-00-00-00-00-00-F8-FF                        NaN
'   107    00-00-00-00-00-00-F0-FF                  -Infinity
'   115    00-00-00-00-00-00-F0-7F                   Infinity

설명

이 메서드는 ToDouble 바이트를 인덱 startIndex 스에서 + 7로 startIndex 값으로 Double 변환합니다. 배열의 바이트 순서는 컴퓨터 시스템 아키텍처의 엔디언성을 반영해야 합니다. 자세한 내용은 클래스 항목의 설명 섹션을 BitConverter 참조하세요.

추가 정보

적용 대상