Freigeben über


Decimal.GetBits-Methode

Konvertiert den Wert einer angegebenen Instanz von Decimal in die entsprechende binäre Darstellung.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function GetBits ( _
    d As Decimal _
) As Integer()
'Usage
Dim d As Decimal
Dim returnValue As Integer()

returnValue = Decimal.GetBits(d)
public static int[] GetBits (
    decimal d
)
public:
static array<int>^ GetBits (
    Decimal d
)
public static int[] GetBits (
    Decimal d
)
public static function GetBits (
    d : decimal
) : int[]

Parameter

Rückgabewert

Ein Array von 32-Bit-Ganzzahlen mit Vorzeichen mit vier Elementen, die die binäre Darstellung von d enthalten.

Hinweise

Die binäre Darstellung einer Decimal-Zahl besteht aus einem 1-Bit-Vorzeichen, einer 96-Bit-Ganzzahl und einem Skalierungsfaktor, der zum Dividieren der Ganzzahl verwendet wird und angibt, welcher Teil ein Dezimalbruch ist. Der Skalierungsfaktor ist implizit 10 mit einem Exponenten zwischen 0 (null) und 28.

Der Rückgabewert ist ein Array von 32-Bit-Ganzzahlen mit Vorzeichen, das aus vier Elementen besteht.

Das erste, zweite und dritte Element des zurückgegebenen Arrays enthält jeweils die unteren, mittleren und oberen 32 Bits der 96-Bit-Ganzzahl.

Das vierte Element des zurückgegebenen Arrays enthält den Skalierungsfaktor und das Vorzeichen. Es besteht aus folgenden Teilen:

Die Bits 0 (null) bis 15 (das niederwertige Wort) werden nicht verwendet und müssen 0 (null) sein.

Die Bits 16 bis 23 müssen einen Exponenten zwischen 0 (null) und 28 enthalten, der die Zehnerpotenz angibt, durch die die Ganzzahl dividiert werden soll.

Die Bits 24 bis 30 werden nicht verwendet und müssen 0 (null) sein.

Das Bit 31 enthält das Vorzeichen, wobei 0 (null) positiv und 1 negativ bedeutet.

Beachten Sie, dass die Bitdarstellung zwischen +0 und -0 unterscheidet. Diese Werte werden bei allen Operationen als gleiche Werte behandelt.

Beispiel

Im folgenden Codebeispiel werden mehrere Decimal-Werte mithilfe der GetBits-Methode in die entsprechenden binären Darstellungen konvertiert.

' Example of the Decimal.GetBits method. 
Imports System
Imports Microsoft.VisualBasic

Module DecimalGetBitsDemo
    
    Const dataFmt As String = _
        "{0,31}  {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}"

    ' Display the Decimal.GetBits argument and the result array.
    Sub ShowDecimalGetBits( Argument As Decimal )

        Dim Bits As Integer( ) = Decimal.GetBits( Argument )

        Console.WriteLine( dataFmt, Argument, _
            Bits( 3 ), Bits( 2 ), Bits( 1 ), Bits( 0 ) )
    End Sub

    Sub Main( )
        Console.WriteLine( "This example of the " & _
            "Decimal.GetBits( Decimal ) method " & vbCrLf & _
            "generates the following output. It displays " & _
            "the argument " & vbCrLf & "as a Decimal and the result " & _
            "array in hexadecimal." & vbCrLf )
        Console.WriteLine( dataFmt, "Argument", "Bits(3)", _
            "Bits(2)", "Bits(1)", "Bits(0)" )
        Console.WriteLine( dataFmt, "--------", "-------", _
            "-------", "-------", "-------" )

        ' Get internal bits for Decimal objects.
        ShowDecimalGetBits( 1D )
        ShowDecimalGetBits( 100000000000000D )
        ShowDecimalGetBits( 10000000000000000000000000000D )
        ShowDecimalGetBits( _
            Decimal.Parse( "100000000000000.00000000000000" ) )
        ShowDecimalGetBits( _
            Decimal.Parse( "1.0000000000000000000000000000" ) )
        ShowDecimalGetBits( 123456789D ) 
        ShowDecimalGetBits( 0.123456789D ) 
        ShowDecimalGetBits( 0.000000000123456789D ) 
        ShowDecimalGetBits( 0.000000000000000000123456789D ) 
        ShowDecimalGetBits( 4294967295D ) 
        ShowDecimalGetBits( 18446744073709551615D ) 
        ShowDecimalGetBits( Decimal.MaxValue ) 
        ShowDecimalGetBits( Decimal.MinValue ) 
        ShowDecimalGetBits( -7.9228162514264337593543950335D ) 
    End Sub
End Module 

' This example of the Decimal.GetBits( Decimal ) method
' generates the following output. It displays the argument
' as a Decimal and the result array in hexadecimal.
' 
'                        Argument     Bits(3)   Bits(2)   Bits(1)   Bits(0)
'                        --------     -------   -------   -------   -------
'                               1    00000000  00000000  00000000  00000001
'                 100000000000000    00000000  00000000  00005AF3  107A4000
'   10000000000000000000000000000    00000000  204FCE5E  3E250261  10000000
'  100000000000000.00000000000000    000E0000  204FCE5E  3E250261  10000000
'  1.0000000000000000000000000000    001C0000  204FCE5E  3E250261  10000000
'                       123456789    00000000  00000000  00000000  075BCD15
'                     0.123456789    00090000  00000000  00000000  075BCD15
'            0.000000000123456789    00120000  00000000  00000000  075BCD15
'   0.000000000000000000123456789    001B0000  00000000  00000000  075BCD15
'                      4294967295    00000000  00000000  00000000  FFFFFFFF
'            18446744073709551615    00000000  00000000  FFFFFFFF  FFFFFFFF
'   79228162514264337593543950335    00000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
'  -79228162514264337593543950335    80000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
' -7.9228162514264337593543950335    801C0000  FFFFFFFF  FFFFFFFF  FFFFFFFF
// Example of the decimal.GetBits method. 
using System;

class DecimalGetBitsDemo
{
    const string dataFmt = "{0,31}  {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}";

    // Display the decimal.GetBits argument and the result array.
    public static void ShowDecimalGetBits( decimal Argument )
    {
        int[ ] Bits = decimal.GetBits( Argument );

        Console.WriteLine( dataFmt, Argument, 
            Bits[ 3 ], Bits[ 2 ], Bits[ 1 ], Bits[ 0 ] );
    }

    public static void Main( )
    {
        Console.WriteLine( "This example of the " +
            "decimal.GetBits( decimal ) method \ngenerates the " +
            "following output. It displays the argument \nas a " +
            "decimal and the result array in hexadecimal.\n" );
        Console.WriteLine( dataFmt, "Argument", "Bits[3]", 
            "Bits[2]", "Bits[1]", "Bits[0]" );
        Console.WriteLine( dataFmt, "--------", "-------", 
            "-------", "-------", "-------" );

        // Get internal bits for decimal objects.
        ShowDecimalGetBits( 1M );
        ShowDecimalGetBits( 100000000000000M );
        ShowDecimalGetBits( 10000000000000000000000000000M );
        ShowDecimalGetBits( 100000000000000.00000000000000M );
        ShowDecimalGetBits( 1.0000000000000000000000000000M );
        ShowDecimalGetBits( 123456789M );
        ShowDecimalGetBits( 0.123456789M );
        ShowDecimalGetBits( 0.000000000123456789M );
        ShowDecimalGetBits( 0.000000000000000000123456789M );
        ShowDecimalGetBits( 4294967295M );
        ShowDecimalGetBits( 18446744073709551615M );
        ShowDecimalGetBits( decimal.MaxValue );
        ShowDecimalGetBits( decimal.MinValue );
        ShowDecimalGetBits( -7.9228162514264337593543950335M );
    }
}

/*
This example of the decimal.GetBits( decimal ) method
generates the following output. It displays the argument
as a decimal and the result array in hexadecimal.

                       Argument     Bits[3]   Bits[2]   Bits[1]   Bits[0]
                       --------     -------   -------   -------   -------
                              1    00000000  00000000  00000000  00000001
                100000000000000    00000000  00000000  00005AF3  107A4000
  10000000000000000000000000000    00000000  204FCE5E  3E250261  10000000
 100000000000000.00000000000000    000E0000  204FCE5E  3E250261  10000000
 1.0000000000000000000000000000    001C0000  204FCE5E  3E250261  10000000
                      123456789    00000000  00000000  00000000  075BCD15
                    0.123456789    00090000  00000000  00000000  075BCD15
           0.000000000123456789    00120000  00000000  00000000  075BCD15
  0.000000000000000000123456789    001B0000  00000000  00000000  075BCD15
                     4294967295    00000000  00000000  00000000  FFFFFFFF
           18446744073709551615    00000000  00000000  FFFFFFFF  FFFFFFFF
  79228162514264337593543950335    00000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
 -79228162514264337593543950335    80000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
-7.9228162514264337593543950335    801C0000  FFFFFFFF  FFFFFFFF  FFFFFFFF
*/
// Example of the Decimal::GetBits method. 
using namespace System;
const __wchar_t * dataFmt = L"{0,31}  {1,10:X8}{2,10:X8}{3,10:X8}{4,10:X8}";

// Display the Decimal::GetBits argument and the result array.
void ShowDecimalGetBits( Decimal Argument )
{
   array<int>^Bits = Decimal::GetBits( Argument );
   Console::WriteLine( gcnew String( dataFmt ), Argument, Bits[ 3 ], Bits[ 2 ], Bits[ 1 ], Bits[ 0 ] );
}

int main()
{
   Console::WriteLine( "This example of the "
   "Decimal::GetBits( Decimal ) method \ngenerates the "
   "following output. It displays the argument \nas a "
   "Decimal and the result array in hexadecimal.\n" );
   Console::WriteLine( gcnew String( dataFmt ), "Argument", "Bits[3]", "Bits[2]", "Bits[1]", "Bits[0]" );
   Console::WriteLine( gcnew String( dataFmt ), "--------", "-------", "-------", "-------", "-------" );
   
   // Get internal bits for Decimal objects.
   ShowDecimalGetBits( Decimal::Parse( "1" ) );
   ShowDecimalGetBits( Decimal::Parse( "100000000000000" ) );
   ShowDecimalGetBits( Decimal::Parse( "10000000000000000000000000000" ) );
   ShowDecimalGetBits( Decimal::Parse( "100000000000000.00000000000000" ) );
   ShowDecimalGetBits( Decimal::Parse( "1.0000000000000000000000000000" ) );
   ShowDecimalGetBits( Decimal::Parse( "123456789" ) );
   ShowDecimalGetBits( Decimal::Parse( "0.123456789" ) );
   ShowDecimalGetBits( Decimal::Parse( "0.000000000123456789" ) );
   ShowDecimalGetBits( Decimal::Parse( "0.000000000000000000123456789" ) );
   ShowDecimalGetBits( Decimal::Parse( "4294967295" ) );
   ShowDecimalGetBits( Decimal::Parse( "18446744073709551615" ) );
   ShowDecimalGetBits( Decimal::MaxValue );
   ShowDecimalGetBits( Decimal::MinValue );
   ShowDecimalGetBits( Decimal::Parse( "-7.9228162514264337593543950335" ) );
}

/*
This example of the Decimal::GetBits( Decimal ) method
generates the following output. It displays the argument
as a Decimal and the result array in hexadecimal.

                       Argument     Bits[3]   Bits[2]   Bits[1]   Bits[0]
                       --------     -------   -------   -------   -------
                              1    00000000  00000000  00000000  00000001
                100000000000000    00000000  00000000  00005AF3  107A4000
  10000000000000000000000000000    00000000  204FCE5E  3E250261  10000000
 100000000000000.00000000000000    000E0000  204FCE5E  3E250261  10000000
 1.0000000000000000000000000000    001C0000  204FCE5E  3E250261  10000000
                      123456789    00000000  00000000  00000000  075BCD15
                    0.123456789    00090000  00000000  00000000  075BCD15
           0.000000000123456789    00120000  00000000  00000000  075BCD15
  0.000000000000000000123456789    001B0000  00000000  00000000  075BCD15
                     4294967295    00000000  00000000  00000000  FFFFFFFF
           18446744073709551615    00000000  00000000  FFFFFFFF  FFFFFFFF
  79228162514264337593543950335    00000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
 -79228162514264337593543950335    80000000  FFFFFFFF  FFFFFFFF  FFFFFFFF
-7.9228162514264337593543950335    801C0000  FFFFFFFF  FFFFFFFF  FFFFFFFF
*/

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Decimal-Struktur
Decimal-Member
System-Namespace
Decimal