當前位置: 首頁>>代碼示例>>C#>>正文


C# BigInteger構造函數代碼示例

本文整理匯總了C#中System.Numerics.BigInteger.BigInteger構造函數的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger構造函數的具體用法?C# BigInteger怎麽用?C# BigInteger使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在System.Numerics.BigInteger的用法示例。


在下文中一共展示了BigInteger構造函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BigInteger

byte[] bytes = { 5, 4, 3, 2, 1 };
BigInteger number = new BigInteger(bytes);
Console.WriteLine("The value of number is {0} (or 0x{0:x}).", number);
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:3,代碼來源:BigInteger

輸出:

The value of number is 4328719365 (or 0x102030405).

示例2: foreach

// Instantiate BigInteger values.
BigInteger positiveValue = BigInteger.Parse("4713143110832790377889");
BigInteger negativeValue = BigInteger.Add(-Int64.MaxValue, -60000); 
BigInteger positiveValue2, negativeValue2;

// Create two byte arrays.
byte[] positiveBytes = positiveValue.ToByteArray();
byte[] negativeBytes = negativeValue.ToByteArray();

// Instantiate new BigInteger from negativeBytes array.
Console.Write("Converted {0:N0} to the byte array ", negativeValue);
foreach (byte byteValue in negativeBytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
negativeValue2 = new BigInteger(negativeBytes);
Console.WriteLine("Converted the byte array to {0:N0}", negativeValue2);
Console.WriteLine();

// Instantiate new BigInteger from positiveBytes array.
Console.Write("Converted {0:N0} to the byte array ", positiveValue);
foreach (byte byteValue in positiveBytes)
   Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
positiveValue2 = new BigInteger(positiveBytes);
Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2);
Console.WriteLine();
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:26,代碼來源:BigInteger

輸出:

Converted -9,223,372,036,854,835,807 to the byte array A1 15 FF FF FF FF FF 7F FF
Converted the byte array to -9,223,372,036,854,835,807

Converted 4,713,143,110,832,790,377,889 to the byte array A1 15 FF FF FF FF FF 7F FF 00
Converted the byte array to 4,713,143,110,832,790,377,889

示例3: if

ulong originalNumber = UInt64.MaxValue;
byte[] bytes = BitConverter.GetBytes(originalNumber);
if (originalNumber > 0 && (bytes[bytes.Length - 1] & 0x80) > 0) 
{
   byte[] temp = new byte[bytes.Length];
   Array.Copy(bytes, temp, bytes.Length);
   bytes = new byte[temp.Length + 1];
   Array.Copy(temp, bytes, temp.Length);
}

BigInteger newNumber = new BigInteger(bytes);
Console.WriteLine("Converted the UInt64 value {0:N0} to {1:N0}.", 
                  originalNumber, newNumber);
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:13,代碼來源:BigInteger

輸出:

Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.

示例4: foreach

decimal[] decimalValues = { -1790.533m, -15.1514m, 18903.79m, 9180098.003m };
foreach (decimal decimalValue in decimalValues)
{
   BigInteger number = new BigInteger(decimalValue);
   Console.WriteLine("Instantiated BigInteger value {0} from the Decimal value {1}.",
                     number, decimalValue);
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:7,代碼來源:BigInteger

輸出:

Instantiated BigInteger value -1790 from the Decimal value -1790.533.
Instantiated BigInteger value -15 from the Decimal value -15.1514.
Instantiated BigInteger value 18903 from the Decimal value 18903.79.
Instantiated BigInteger value 9180098 from the Decimal value 9180098.003.

示例5: BigInteger

// Create a BigInteger from a large double value.
double doubleValue = -6e20;
BigInteger bigIntValue = new BigInteger(doubleValue);
Console.WriteLine("Original Double value: {0:N0}", doubleValue);
Console.WriteLine("Original BigInteger value: {0:N0}", bigIntValue);
// Increment and then display both values.
doubleValue++;
bigIntValue += BigInteger.One;
Console.WriteLine("Incremented Double value: {0:N0}", doubleValue);
Console.WriteLine("Incremented BigInteger value: {0:N0}", bigIntValue);
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:10,代碼來源:BigInteger

輸出:

Original Double value: -600,000,000,000,000,000,000
Original BigInteger value: -600,000,000,000,000,000,000
Incremented Double value: -600,000,000,000,000,000,000
Incremented BigInteger value: -599,999,999,999,999,999,999

示例6: foreach

int[] integers = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                   Int32.MaxValue };
BigInteger constructed, assigned;

foreach (int number in integers)
{
   constructed = new BigInteger(number);
   assigned = number;
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)); 
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:11,代碼來源:BigInteger

輸出:

-2147483648 = -2147483648: True
-10534 = -10534: True
-189 = -189: True
0 = 0: True
17 = 17: True
113439 = 113439: True
2147483647 = 2147483647: True

示例7: foreach

long[] longs = { Int64.MinValue, -10534, -189, 0, 17, 113439,
                 Int64.MaxValue };
BigInteger constructed, assigned;

foreach (long number in longs)
{
   constructed = new BigInteger(number);
   assigned = number;
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)); 
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:11,代碼來源:BigInteger

輸出:

-2147483648 = -2147483648: True
-10534 = -10534: True
-189 = -189: True
0 = 0: True
17 = 17: True
113439 = 113439: True
2147483647 = 2147483647: True

示例8: BigInteger

// Create a BigInteger from a large negative Single value
float negativeSingle = Single.MinValue;
BigInteger negativeNumber = new BigInteger(negativeSingle);

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));

negativeSingle++;
negativeNumber++;

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:12,代碼來源:BigInteger

輸出:

-340,282,300,000,000,000,000,000,000,000,000,000,000
-340,282,346,638,528,859,811,704,183,484,516,925,440
-340,282,300,000,000,000,000,000,000,000,000,000,000
-340,282,346,638,528,859,811,704,183,484,516,925,439

示例9: foreach

uint[] unsignedValues = { 0, 16704, 199365, UInt32.MaxValue };
foreach (uint unsignedValue in unsignedValues)
{
   BigInteger constructedNumber = new BigInteger(unsignedValue);
   BigInteger assignedNumber = unsignedValue;
   if (constructedNumber.Equals(assignedNumber))
      Console.WriteLine("Both methods create a BigInteger whose value is {0:N0}.",
                        constructedNumber);
   else
      Console.WriteLine("{0:N0} ≠ {1:N0}", constructedNumber, assignedNumber);
}
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:11,代碼來源:BigInteger

輸出:

Both methods create a BigInteger whose value is 0.
Both methods create a BigInteger whose value is 16,704.
Both methods create a BigInteger whose value is 199,365.
Both methods create a BigInteger whose value is 4,294,967,295.

示例10: BigInteger

ulong unsignedValue = UInt64.MaxValue;
BigInteger number = new BigInteger(unsignedValue);
Console.WriteLine(number.ToString("N0"));
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:3,代碼來源:BigInteger

輸出:

18,446,744,073,709,551,615


注:本文中的System.Numerics.BigInteger.BigInteger構造函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。