Decimal の新しいインスタンスの値を、指定した配列に格納されている、バイナリ形式の 10 進値に初期化します。
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
bits As Integer() _
)
'使用
Dim bits As Integer()
Dim instance As New Decimal(bits)
public Decimal (
int[] bits
)
public:
Decimal (
array<int>^ bits
)
public Decimal (
int[] bits
)
public function Decimal (
bits : int[]
)
パラメータ
- bits
10 進値形式を格納している 32 ビット符号付き整数の配列。
例外
例外の種類 | 条件 |
---|---|
bits が null 参照 (Visual Basic では Nothing) です。 |
|
bits の長さが 4 ではありません。 または bits の 10 進値形式が有効ではありません。 |
解説
Decimal 数値のバイナリ表現は、1 ビットの符号、96 ビットの整数、および整数値を除算し、小数部を指定するために使用するスケール ファクタから構成されます。スケール ファクタは黙示的に数値 10 になり、0 から 28 の範囲の指数で累乗されます。
bits は、32 ビット符号付き整数の 4 要素長配列です。
bits [0]、bits [1]、および bits [2] は、96 ビット整数の下位 32 ビット、中位 32 ビット、および上位 32 ビットをそれぞれ格納しています。
bits [3] はスケール ファクタと符号を格納し、次に示す部分から構成されます。
ビット 0 ~ 15 の下位ワードは未使用で、0 である必要があります。
ビット 16 ~ 23 には、0 から 28 までの範囲の指数部を格納する必要があります。この指数部は、整数を除算する 10 の累乗を示します。
ビット 24 ~ 30 は未使用で、0 である必要があります。
ビット 31 は符号を格納している必要があります。0 は正、1 は負を表します。
1 つの数値に有効なバイナリ形式がいくつかある場合があり、すべての形式は等しく有効であり、数値として等価です。ビット形式では負の 0 と正の 0 が区別されます。これらの値はすべての演算で等値として扱われます。
使用例
Decimal 構造体を 4 つの Int32 値の配列で初期化するコンストラクタのオーバーロードを使用して、複数の Decimal 数値を作成するコード例を次に示します。
' Example of the Decimal( Integer( ) ) constructor.
Imports System
Imports Microsoft.VisualBasic
Module DecimalCtorIArrDemo
' Get the exception type name; remove the namespace prefix.
Function GetExceptionType( ex As Exception ) As String
Dim exceptionType As String = ex.GetType( ).ToString( )
Return exceptionType.Substring( _
exceptionType.LastIndexOf( "."c ) + 1 )
End Function
' Create a Decimal object and display its value.
Sub CreateDecimal( ByVal bits( ) As Integer )
' Format and save the constructor.
Dim ctor As String = String.Format( "Decimal( {{ &H{0:X}", bits( 0 ) )
Dim valOrExc As String
Dim index As Integer
For index = 1 to bits.Length - 1
ctor &= String.Format( ", &H{0:X}", bits( index ) )
Next index
ctor &= " } )"
' Construct the Decimal value.
Try
Dim decimalNum As New Decimal( bits )
' Format the Decimal value for display.
valOrExc = decimalNum.ToString( )
' Save the exception type if an exception was thrown.
Catch ex As Exception
valOrExc = GetExceptionType( ex )
End Try
' Display the constructor and Decimal value or exception.
Dim ctorLen As Integer = 76 - valOrExc.Length
If ctorLen > ctor.Length Then
' Display the data on one line if it will fit.
Console.WriteLine( "{0}{1}", ctor.PadRight( ctorLen ), _
valOrExc )
' Otherwise, display the data on two lines.
Else
Console.WriteLine( "{0}", ctor )
Console.WriteLine( "{0,76}", valOrExc )
End If
End Sub
Sub Main( )
Console.WriteLine( "This example of the " & _
"Decimal( Integer( ) ) constructor " & _
vbCrLf & "generates the following output." & vbCrLf )
Console.WriteLine( "{0,-38}{1,38}", "Constructor", _
"Value or Exception" )
Console.WriteLine( "{0,-38}{1,38}", "-----------", _
"------------------" )
' Construct Decimal objects from Integer arrays.
CreateDecimal( New Integer( ) { 0, 0, 0, 0 } )
CreateDecimal( New Integer( ) { 0, 0, 0 } )
CreateDecimal( New Integer( ) { 0, 0, 0, 0, 0 } )
CreateDecimal( New Integer( ) { 1000000000, 0, 0, 0 } )
CreateDecimal( New Integer( ) { 0, 1000000000, 0, 0 } )
CreateDecimal( New Integer( ) { 0, 0, 1000000000, 0 } )
CreateDecimal( New Integer( ) { 0, 0, 0, 1000000000 } )
CreateDecimal( New Integer( ) { -1, -1, -1, 0 } )
CreateDecimal( New Integer( ) { -1, -1, -1, &H80000000 } )
CreateDecimal( New Integer( ) { -1, 0, 0, &H100000 } )
CreateDecimal( New Integer( ) { -1, 0, 0, &H1C0000 } )
CreateDecimal( New Integer( ) { -1, 0, 0, &H1D0000 } )
CreateDecimal( New Integer( ) { -1, 0, 0, &H1C0001 } )
CreateDecimal( New Integer( ) _
{ &HF0000, &HF0000, &HF0000, &HF0000 } )
End Sub
End Module
' This example of the Decimal( Integer( ) ) constructor
' generates the following output.
'
' Constructor Value or Exception
' ----------- ------------------
' Decimal( { &H0, &H0, &H0, &H0 } ) 0
' Decimal( { &H0, &H0, &H0 } ) ArgumentException
' Decimal( { &H0, &H0, &H0, &H0, &H0 } ) ArgumentException
' Decimal( { &H3B9ACA00, &H0, &H0, &H0 } ) 1000000000
' Decimal( { &H0, &H3B9ACA00, &H0, &H0 } ) 4294967296000000000
' Decimal( { &H0, &H0, &H3B9ACA00, &H0 } ) 18446744073709551616000000000
' Decimal( { &H0, &H0, &H0, &H3B9ACA00 } ) ArgumentException
' Decimal( { &HFFFFFFFF, &HFFFFFFFF, &HFFFFFFFF, &H0 } )
' 79228162514264337593543950335
' Decimal( { &HFFFFFFFF, &HFFFFFFFF, &HFFFFFFFF, &H80000000 } )
' -79228162514264337593543950335
' Decimal( { &HFFFFFFFF, &H0, &H0, &H100000 } ) 0.0000004294967295
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1C0000 } ) 0.0000000000000000004294967295
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1D0000 } ) ArgumentException
' Decimal( { &HFFFFFFFF, &H0, &H0, &H1C0001 } ) ArgumentException
' Decimal( { &HF0000, &HF0000, &HF0000, &HF0000 } )
' 18133887298.441562272235520
// Example of the decimal( int[ ] ) constructor.
using System;
class DecimalCtorIArrDemo
{
// Get the exception type name; remove the namespace prefix.
public static string GetExceptionType( Exception ex )
{
string exceptionType = ex.GetType( ).ToString( );
return exceptionType.Substring(
exceptionType.LastIndexOf( '.' ) + 1 );
}
// Create a decimal object and display its value.
public static void CreateDecimal( int[ ] bits )
{
// Format the constructor for display.
string ctor = String.Format(
"decimal( {{ 0x{0:X}", bits[ 0 ] );
string valOrExc;
for( int index = 1; index < bits.Length; index++ )
ctor += String.Format( ", 0x{0:X}", bits[ index ] );
ctor += " } )";
try
{
// Construct the decimal value.
decimal decimalNum = new decimal( bits );
// Format the decimal value for display.
valOrExc = decimalNum.ToString( );
}
catch( Exception ex )
{
// Save the exception type if an exception was thrown.
valOrExc = GetExceptionType( ex );
}
// Display the constructor and decimal value or exception.
int ctorLen = 76 - valOrExc.Length;
// Display the data on one line if it will fit.
if( ctorLen > ctor.Length )
Console.WriteLine( "{0}{1}", ctor.PadRight( ctorLen ),
valOrExc );
// Otherwise, display the data on two lines.
else
{
Console.WriteLine( "{0}", ctor );
Console.WriteLine( "{0,76}", valOrExc );
}
}
public static void Main( )
{
Console.WriteLine(
"This example of the decimal( int[ ] ) constructor " +
"\ngenerates the following output.\n" );
Console.WriteLine( "{0,-38}{1,38}", "Constructor",
"Value or Exception" );
Console.WriteLine( "{0,-38}{1,38}", "-----------",
"------------------" );
// Construct decimal objects from integer arrays.
CreateDecimal( new int[ ] { 0, 0, 0, 0 } );
CreateDecimal( new int[ ] { 0, 0, 0 } );
CreateDecimal( new int[ ] { 0, 0, 0, 0, 0 } );
CreateDecimal( new int[ ] { 1000000000, 0, 0, 0 } );
CreateDecimal( new int[ ] { 0, 1000000000, 0, 0 } );
CreateDecimal( new int[ ] { 0, 0, 1000000000, 0 } );
CreateDecimal( new int[ ] { 0, 0, 0, 1000000000 } );
CreateDecimal( new int[ ] { -1, -1, -1, 0 } );
CreateDecimal( new int[ ]
{ -1, -1, -1, unchecked( (int)0x80000000 ) } );
CreateDecimal( new int[ ] { -1, 0, 0, 0x100000 } );
CreateDecimal( new int[ ] { -1, 0, 0, 0x1C0000 } );
CreateDecimal( new int[ ] { -1, 0, 0, 0x1D0000 } );
CreateDecimal( new int[ ] { -1, 0, 0, 0x1C0001 } );
CreateDecimal( new int[ ]
{ 0xF0000, 0xF0000, 0xF0000, 0xF0000 } );
}
}
/*
This example of the decimal( int[ ] ) constructor
generates the following output.
Constructor Value or Exception
----------- ------------------
decimal( { 0x0, 0x0, 0x0, 0x0 } ) 0
decimal( { 0x0, 0x0, 0x0 } ) ArgumentException
decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } ) ArgumentException
decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } ) 1000000000
decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } ) 4294967296000000000
decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } ) 18446744073709551616000000000
decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } ) ArgumentException
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
-79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } ) 0.0000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } ) ArgumentException
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } ) ArgumentException
decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
18133887298.441562272235520
*/
// Example of the Decimal( int __gc [ ] ) constructor.
using namespace System;
// Get the exception type name; remove the namespace prefix.
String^ GetExceptionType( Exception^ ex )
{
String^ exceptionType = ex->GetType()->ToString();
return exceptionType->Substring( exceptionType->LastIndexOf( '.' ) + 1 );
}
// Create a Decimal object and display its value.
void CreateDecimal( array<int>^bits )
{
// Format the constructor for display.
String^ ctor = String::Format( "Decimal( {{ 0x{0:X}", bits[ 0 ] );
String^ valOrExc;
for ( int index = 1; index < bits->Length; index++ )
ctor = String::Concat( ctor, String::Format( ", 0x{0:X}", bits[ index ] ) );
ctor = String::Concat( ctor, " } )" );
try
{
// Construct the Decimal value.
Decimal decimalNum = Decimal(bits);
// Format the Decimal value for display.
valOrExc = decimalNum.ToString();
}
catch ( Exception^ ex )
{
// Save the exception type if an exception was thrown.
valOrExc = GetExceptionType( ex );
}
// Display the constructor and Decimal value or exception.
int ctorLen = 76 - valOrExc->Length;
// Display the data on one line if it will fit.
if ( ctorLen > ctor->Length )
Console::WriteLine( "{0}{1}", ctor->PadRight( ctorLen ), valOrExc );
// Otherwise, display the data on two lines.
else
{
Console::WriteLine( "{0}", ctor );
Console::WriteLine( "{0,76}", valOrExc );
}
}
int main()
{
Console::WriteLine( "This example of the Decimal( int __gc [ ] ) "
"constructor \ngenerates the following output.\n" );
Console::WriteLine( "{0,-38}{1,38}", "Constructor", "Value or Exception" );
Console::WriteLine( "{0,-38}{1,38}", "-----------", "------------------" );
// Construct Decimal objects from integer arrays.
array<Int32>^zero = {0,0,0,0};
CreateDecimal( zero );
array<Int32>^arrayShort = {0,0,0};
CreateDecimal( arrayShort );
array<Int32>^arrayLong = {0,0,0,0,0};
CreateDecimal( arrayLong );
array<Int32>^word0Data = {1000000000,0,0,0};
CreateDecimal( word0Data );
array<Int32>^word1Data = {0,1000000000,0,0};
CreateDecimal( word1Data );
array<Int32>^word2Data = {0,0,1000000000,0};
CreateDecimal( word2Data );
array<Int32>^word3Data = {0,0,0,1000000000};
CreateDecimal( word3Data );
array<Int32>^decMax = { -1,-1,-1,0};
CreateDecimal( decMax );
array<Int32>^decMin = { -1,-1,-1,0x80000000};
CreateDecimal( decMin );
array<Int32>^fracDig16 = { -1,0,0,0x100000};
CreateDecimal( fracDig16 );
array<Int32>^fracDig28 = { -1,0,0,0x1C0000};
CreateDecimal( fracDig28 );
array<Int32>^fracDig29 = { -1,0,0,0x1D0000};
CreateDecimal( fracDig29 );
array<Int32>^reserved = { -1,0,0,0x1C0001};
CreateDecimal( reserved );
array<Int32>^Same4Words = {0xF0000,0xF0000,0xF0000,0xF0000};
CreateDecimal( Same4Words );
}
/*
This example of the Decimal( int __gc [ ] ) constructor
generates the following output.
Constructor Value or Exception
----------- ------------------
Decimal( { 0x0, 0x0, 0x0, 0x0 } ) 0
Decimal( { 0x0, 0x0, 0x0 } ) ArgumentException
Decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } ) ArgumentException
Decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } ) 1000000000
Decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } ) 4294967296000000000
Decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } ) 18446744073709551616000000000
Decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } ) ArgumentException
Decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
79228162514264337593543950335
Decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
-79228162514264337593543950335
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } ) 0.0000004294967295
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } ) ArgumentException
Decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } ) ArgumentException
Decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
18133887298.441562272235520
*/
// Example of the decimal( int[ ] ) constructor.
import System.* ;
class DecimalCtorIArrDemo
{
// Get the exception type name; remove the namespace prefix.
public static String GetExceptionType(System.Exception ex)
{
String exceptionType = ex.GetType().ToString();
return exceptionType.Substring((exceptionType.LastIndexOf('.') + 1));
} //GetExceptionType
// Create a decimal object and display its value.
public static void CreateDecimal(int[] bits)
{
// Format the constructor for display.
String ctor = String.Format("decimal( {{ 0x{0:X}", bits.get_Item(0));
String valOrExc;
for (int index = 1; index < bits.length; index++) {
ctor += String.Format(", 0x{0:X}", bits.get_Item(index));
}
ctor += " } )";
try {
// Construct the decimal value.
System.Decimal decimalNum = new System.Decimal(bits);
// Format the decimal value for display.
valOrExc = decimalNum.ToString();
}
catch (System.Exception ex) {
// Save the exception type if an exception was thrown.
valOrExc = System.Convert.ToString(GetExceptionType(ex));
}
// Display the constructor and decimal value or exception.
int ctorLen = 76 - valOrExc.get_Length();
// Display the data on one line if it will fit.
if (ctorLen > ctor.get_Length()) {
Console.WriteLine("{0}{1}", ctor.PadRight(ctorLen), valOrExc);
}
// Otherwise, display the data on two lines.
else {
Console.WriteLine("{0}", ctor);
Console.WriteLine("{0,76}", valOrExc);
}
} //CreateDecimal
public static void main(String[] args)
{
Console.WriteLine(("This example of the decimal( int[ ] ) constructor "
+ "\ngenerates the following output.\n"));
Console.WriteLine("{0,-38}{1,38}", "Constructor", "Value or Exception");
Console.WriteLine("{0,-38}{1,38}", "-----------", "------------------");
// Construct decimal objects from integer arrays.
CreateDecimal(new int[] { 0, 0, 0, 0 });
CreateDecimal(new int[] { 0, 0, 0 });
CreateDecimal(new int[] { 0, 0, 0, 0, 0 });
CreateDecimal(new int[] { 1000000000, 0, 0, 0 });
CreateDecimal(new int[] { 0, 1000000000, 0, 0 });
CreateDecimal(new int[] { 0, 0, 1000000000, 0 });
CreateDecimal(new int[] { 0, 0, 0, 1000000000 });
CreateDecimal(new int[] { -1, -1, -1, 0 });
CreateDecimal(new int[] { -1, -1, -1, (int)(0x80000000) });
CreateDecimal(new int[] { -1, 0, 0, 0x100000 });
CreateDecimal(new int[] { -1, 0, 0, 0x1C0000 });
CreateDecimal(new int[] { -1, 0, 0, 0x1D0000 });
CreateDecimal(new int[] { -1, 0, 0, 0x1C0001 });
CreateDecimal(new int[] { 0xF0000, 0xF0000, 0xF0000, 0xF0000 });
} //main
} //DecimalCtorIArrDemo
/*
This example of the decimal( int[ ] ) constructor
generates the following output.
Constructor Value or Exception
----------- ------------------
decimal( { 0x0, 0x0, 0x0, 0x0 } ) 0
decimal( { 0x0, 0x0, 0x0 } ) ArgumentException
decimal( { 0x0, 0x0, 0x0, 0x0, 0x0 } ) ArgumentException
decimal( { 0x3B9ACA00, 0x0, 0x0, 0x0 } ) 1000000000
decimal( { 0x0, 0x3B9ACA00, 0x0, 0x0 } ) 4294967296000000000
decimal( { 0x0, 0x0, 0x3B9ACA00, 0x0 } ) 18446744073709551616000000000
decimal( { 0x0, 0x0, 0x0, 0x3B9ACA00 } ) ArgumentException
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x0 } )
79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x80000000 } )
-79228162514264337593543950335
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x100000 } ) 0.0000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0000 } ) 0.0000000000000000004294967295
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1D0000 } ) ArgumentException
decimal( { 0xFFFFFFFF, 0x0, 0x0, 0x1C0001 } ) ArgumentException
decimal( { 0xF0000, 0xF0000, 0xF0000, 0xF0000 } )
18133887298.441562272235520
*/
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0