本文整理汇总了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);
输出:
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();
输出:
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);
输出:
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);
}
输出:
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);
输出:
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));
}
输出:
-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));
}
输出:
-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"));
输出:
-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);
}
输出:
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"));
输出:
18,446,744,073,709,551,615