指定した Decimal のインスタンスの値を、それと等価のバイナリ形式に変換します。
Public Shared Function GetBits( _
ByVal d As Decimal _) As Integer()
[C#]
public static int[] GetBits(decimald);
[C++]
public: static int GetBits(Decimald) __gc[];
[JScript]
public static function GetBits(
d : Decimal) : int[];
パラメータ
- d
Decimal 値。
戻り値
d のバイナリ形式を格納している 4 要素長の 32 ビット符号付き整数配列。
解説
Decimal 数値のバイナリ表現は、1 ビットの符号、96 ビットの整数、および整数値を除算し、小数部を指定するために使用するスケール ファクタから構成されます。スケール ファクタは黙示的に数値 10 になり、0 から 28 の範囲の指数で累乗されます。
戻り値は、4 要素長の 32 ビット符号付き整数配列です。
この配列の 1 ~ 3 番目の要素は、96 ビット整数の下位 32 ビット、中位 32 ビット、および上位 32 ビットをそれぞれ格納しています。
4 番目の要素は、スケール ファクタと符号を格納しています。この要素は、次に示す部分から構成されています。
ビット 0 ~ 15 の下位ワードは未使用で、0 である必要があります。
ビット 16 ~ 23 は 0 から 28 までの範囲の指数部を格納している必要があります。この指数部は整数を除算する 10 の累乗を示します。
ビット 24 ~ 30 は未使用で、0 である必要があります。
ビット 31 は符号を格納している必要があります。0 は正、1 は負を表します。
ビット形式では負の 0 と正の 0 が区別されます。これらの値はすべての演算で等値として扱われます。
使用例
[Visual Basic, C#, C++] GetBits メソッドを使用して複数の Decimal の値をバイナリ形式の等価の値に変換するコード例を次に示します。
' 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
[C#]
// 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
*/
[C++]
// Example of the Decimal::GetBits method.
#using <mscorlib.dll>
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 )
{
int Bits __gc [ ] = Decimal::GetBits( Argument );
Console::WriteLine( new String( dataFmt ), __box( Argument ),
__box( Bits[ 3 ] ), __box( Bits[ 2 ] ),
__box( Bits[ 1 ] ), __box( Bits[ 0 ] ) );
}
void main( )
{
Console::WriteLine( S"This example of the "
S"Decimal::GetBits( Decimal ) method \ngenerates the "
S"following output. It displays the argument \nas a "
S"Decimal and the result array in hexadecimal.\n" );
Console::WriteLine( new String( dataFmt ), S"Argument",
S"Bits[3]", S"Bits[2]", S"Bits[1]", S"Bits[0]" );
Console::WriteLine( new String( dataFmt ), S"--------",
S"-------", S"-------", S"-------", S"-------" );
// Get internal bits for Decimal objects.
ShowDecimalGetBits( Decimal::Parse( S"1" ) );
ShowDecimalGetBits( Decimal::Parse( S"100000000000000" ) );
ShowDecimalGetBits(
Decimal::Parse( S"10000000000000000000000000000" ) );
ShowDecimalGetBits(
Decimal::Parse( S"100000000000000.00000000000000" ) );
ShowDecimalGetBits(
Decimal::Parse( S"1.0000000000000000000000000000" ) );
ShowDecimalGetBits( Decimal::Parse( S"123456789" ) );
ShowDecimalGetBits( Decimal::Parse( S"0.123456789" ) );
ShowDecimalGetBits( Decimal::Parse( S"0.000000000123456789" ) );
ShowDecimalGetBits(
Decimal::Parse( S"0.000000000000000000123456789" ) );
ShowDecimalGetBits( Decimal::Parse( S"4294967295" ) );
ShowDecimalGetBits( Decimal::Parse( S"18446744073709551615" ) );
ShowDecimalGetBits( Decimal::MaxValue );
ShowDecimalGetBits( Decimal::MinValue );
ShowDecimalGetBits(
Decimal::Parse( S"-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
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard