BigInteger 结构

定义

表示任意大有符号整数。

public value class BigInteger : IComparable, IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IFormattable
public value class BigInteger : IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IParsable<System::Numerics::BigInteger>, ISpanParsable<System::Numerics::BigInteger>, IUtf8SpanParsable<System::Numerics::BigInteger>, System::Numerics::IAdditionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IAdditiveIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IBinaryInteger<System::Numerics::BigInteger>, System::Numerics::IBinaryNumber<System::Numerics::BigInteger>, System::Numerics::IBitwiseOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IComparisonOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IDecrementOperators<System::Numerics::BigInteger>, System::Numerics::IDivisionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IEqualityOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IIncrementOperators<System::Numerics::BigInteger>, System::Numerics::IModulusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplicativeIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplyOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::INumber<System::Numerics::BigInteger>, System::Numerics::INumberBase<System::Numerics::BigInteger>, System::Numerics::IShiftOperators<System::Numerics::BigInteger, int, System::Numerics::BigInteger>, System::Numerics::ISignedNumber<System::Numerics::BigInteger>, System::Numerics::ISubtractionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryNegationOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryPlusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>
public value class BigInteger : IComparable, IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, ISpanFormattable
public value class BigInteger : IComparable<System::Numerics::BigInteger>, IEquatable<System::Numerics::BigInteger>, IParsable<System::Numerics::BigInteger>, ISpanParsable<System::Numerics::BigInteger>, System::Numerics::IAdditionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IAdditiveIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IBinaryInteger<System::Numerics::BigInteger>, System::Numerics::IBinaryNumber<System::Numerics::BigInteger>, System::Numerics::IBitwiseOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IComparisonOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IDecrementOperators<System::Numerics::BigInteger>, System::Numerics::IDivisionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IEqualityOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, bool>, System::Numerics::IIncrementOperators<System::Numerics::BigInteger>, System::Numerics::IModulusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplicativeIdentity<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IMultiplyOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::INumber<System::Numerics::BigInteger>, System::Numerics::INumberBase<System::Numerics::BigInteger>, System::Numerics::IShiftOperators<System::Numerics::BigInteger, int, System::Numerics::BigInteger>, System::Numerics::ISignedNumber<System::Numerics::BigInteger>, System::Numerics::ISubtractionOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryNegationOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>, System::Numerics::IUnaryPlusOperators<System::Numerics::BigInteger, System::Numerics::BigInteger>
public struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
public readonly struct BigInteger : IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IParsable<System.Numerics.BigInteger>, ISpanParsable<System.Numerics.BigInteger>, IUtf8SpanParsable<System.Numerics.BigInteger>, System.Numerics.IAdditionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IAdditiveIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IBinaryInteger<System.Numerics.BigInteger>, System.Numerics.IBinaryNumber<System.Numerics.BigInteger>, System.Numerics.IBitwiseOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IComparisonOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IDecrementOperators<System.Numerics.BigInteger>, System.Numerics.IDivisionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IEqualityOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IIncrementOperators<System.Numerics.BigInteger>, System.Numerics.IModulusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplicativeIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplyOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.INumber<System.Numerics.BigInteger>, System.Numerics.INumberBase<System.Numerics.BigInteger>, System.Numerics.IShiftOperators<System.Numerics.BigInteger,int,System.Numerics.BigInteger>, System.Numerics.ISignedNumber<System.Numerics.BigInteger>, System.Numerics.ISubtractionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryNegationOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryPlusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>
public readonly struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
public readonly struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, ISpanFormattable
public readonly struct BigInteger : IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IParsable<System.Numerics.BigInteger>, ISpanParsable<System.Numerics.BigInteger>, System.Numerics.IAdditionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IAdditiveIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IBinaryInteger<System.Numerics.BigInteger>, System.Numerics.IBinaryNumber<System.Numerics.BigInteger>, System.Numerics.IBitwiseOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IComparisonOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IDecrementOperators<System.Numerics.BigInteger>, System.Numerics.IDivisionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IEqualityOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,bool>, System.Numerics.IIncrementOperators<System.Numerics.BigInteger>, System.Numerics.IModulusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplicativeIdentity<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IMultiplyOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.INumber<System.Numerics.BigInteger>, System.Numerics.INumberBase<System.Numerics.BigInteger>, System.Numerics.IShiftOperators<System.Numerics.BigInteger,int,System.Numerics.BigInteger>, System.Numerics.ISignedNumber<System.Numerics.BigInteger>, System.Numerics.ISubtractionOperators<System.Numerics.BigInteger,System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryNegationOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>, System.Numerics.IUnaryPlusOperators<System.Numerics.BigInteger,System.Numerics.BigInteger>
[System.Serializable]
public struct BigInteger : IComparable, IComparable<System.Numerics.BigInteger>, IEquatable<System.Numerics.BigInteger>, IFormattable
type BigInteger = struct
    interface IFormattable
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
type BigInteger = struct
    interface ISpanFormattable
    interface IFormattable
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
type BigInteger = struct
    interface IFormattable
    interface IParsable<BigInteger>
    interface ISpanFormattable
    interface ISpanParsable<BigInteger>
    interface IAdditionOperators<BigInteger, BigInteger, BigInteger>
    interface IAdditiveIdentity<BigInteger, BigInteger>
    interface IBinaryInteger<BigInteger>
    interface IBinaryNumber<BigInteger>
    interface IBitwiseOperators<BigInteger, BigInteger, BigInteger>
    interface IComparisonOperators<BigInteger, BigInteger, bool>
    interface IEqualityOperators<BigInteger, BigInteger, bool>
    interface IDecrementOperators<BigInteger>
    interface IDivisionOperators<BigInteger, BigInteger, BigInteger>
    interface IIncrementOperators<BigInteger>
    interface IModulusOperators<BigInteger, BigInteger, BigInteger>
    interface IMultiplicativeIdentity<BigInteger, BigInteger>
    interface IMultiplyOperators<BigInteger, BigInteger, BigInteger>
    interface INumber<BigInteger>
    interface INumberBase<BigInteger>
    interface ISubtractionOperators<BigInteger, BigInteger, BigInteger>
    interface IUnaryNegationOperators<BigInteger, BigInteger>
    interface IUnaryPlusOperators<BigInteger, BigInteger>
    interface IUtf8SpanFormattable
    interface IUtf8SpanParsable<BigInteger>
    interface IShiftOperators<BigInteger, int, BigInteger>
    interface ISignedNumber<BigInteger>
[<System.Serializable>]
type BigInteger = struct
    interface IFormattable
Public Structure BigInteger
Implements IComparable, IComparable(Of BigInteger), IEquatable(Of BigInteger), IFormattable
Public Structure BigInteger
Implements IAdditionOperators(Of BigInteger, BigInteger, BigInteger), IAdditiveIdentity(Of BigInteger, BigInteger), IBinaryInteger(Of BigInteger), IBinaryNumber(Of BigInteger), IBitwiseOperators(Of BigInteger, BigInteger, BigInteger), IComparable(Of BigInteger), IComparisonOperators(Of BigInteger, BigInteger, Boolean), IDecrementOperators(Of BigInteger), IDivisionOperators(Of BigInteger, BigInteger, BigInteger), IEqualityOperators(Of BigInteger, BigInteger, Boolean), IEquatable(Of BigInteger), IIncrementOperators(Of BigInteger), IModulusOperators(Of BigInteger, BigInteger, BigInteger), IMultiplicativeIdentity(Of BigInteger, BigInteger), IMultiplyOperators(Of BigInteger, BigInteger, BigInteger), INumber(Of BigInteger), INumberBase(Of BigInteger), IParsable(Of BigInteger), IShiftOperators(Of BigInteger, Integer, BigInteger), ISignedNumber(Of BigInteger), ISpanParsable(Of BigInteger), ISubtractionOperators(Of BigInteger, BigInteger, BigInteger), IUnaryNegationOperators(Of BigInteger, BigInteger), IUnaryPlusOperators(Of BigInteger, BigInteger), IUtf8SpanParsable(Of BigInteger)
Public Structure BigInteger
Implements IComparable, IComparable(Of BigInteger), IEquatable(Of BigInteger), ISpanFormattable
Public Structure BigInteger
Implements IAdditionOperators(Of BigInteger, BigInteger, BigInteger), IAdditiveIdentity(Of BigInteger, BigInteger), IBinaryInteger(Of BigInteger), IBinaryNumber(Of BigInteger), IBitwiseOperators(Of BigInteger, BigInteger, BigInteger), IComparable(Of BigInteger), IComparisonOperators(Of BigInteger, BigInteger, Boolean), IDecrementOperators(Of BigInteger), IDivisionOperators(Of BigInteger, BigInteger, BigInteger), IEqualityOperators(Of BigInteger, BigInteger, Boolean), IEquatable(Of BigInteger), IIncrementOperators(Of BigInteger), IModulusOperators(Of BigInteger, BigInteger, BigInteger), IMultiplicativeIdentity(Of BigInteger, BigInteger), IMultiplyOperators(Of BigInteger, BigInteger, BigInteger), INumber(Of BigInteger), INumberBase(Of BigInteger), IParsable(Of BigInteger), IShiftOperators(Of BigInteger, Integer, BigInteger), ISignedNumber(Of BigInteger), ISpanParsable(Of BigInteger), ISubtractionOperators(Of BigInteger, BigInteger, BigInteger), IUnaryNegationOperators(Of BigInteger, BigInteger), IUnaryPlusOperators(Of BigInteger, BigInteger)
继承
BigInteger
属性
实现
IComparable IComparable<BigInteger> IEquatable<BigInteger> IFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<BigInteger> IParsable<TSelf> ISpanFormattable ISpanParsable<BigInteger> ISpanParsable<TSelf> IUtf8SpanFormattable IUtf8SpanParsable<BigInteger> IUtf8SpanParsable<TSelf> IAdditionOperators<BigInteger,BigInteger,BigInteger> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<BigInteger,BigInteger> IAdditiveIdentity<TSelf,TSelf> IBinaryInteger<BigInteger> IBinaryNumber<BigInteger> IBinaryNumber<TSelf> IBitwiseOperators<BigInteger,BigInteger,BigInteger> IBitwiseOperators<TSelf,TSelf,TSelf> IComparisonOperators<BigInteger,BigInteger,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<BigInteger> IDecrementOperators<TSelf> IDivisionOperators<BigInteger,BigInteger,BigInteger> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<BigInteger,BigInteger,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IIncrementOperators<BigInteger> IIncrementOperators<TSelf> IModulusOperators<BigInteger,BigInteger,BigInteger> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<BigInteger,BigInteger> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<BigInteger,BigInteger,BigInteger> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<BigInteger> INumber<TSelf> INumberBase<BigInteger> INumberBase<TSelf> IShiftOperators<BigInteger,Int32,BigInteger> IShiftOperators<TSelf,Int32,TSelf> ISignedNumber<BigInteger> ISubtractionOperators<BigInteger,BigInteger,BigInteger> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<BigInteger,BigInteger> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<BigInteger,BigInteger> IUnaryPlusOperators<TSelf,TSelf>

注解

BigInteger 类型是一个不可变类型,表示一个任意较大的整数,其理论上的值没有上限或下限。 类型 BigInteger 的成员紧密平行与其他整型类型的成员 (ByteInt16Int32Int64SByteUInt16UInt32UInt64 类型)。 此类型不同于 .NET 中的其他整型类型,这些类型具有由其 MinValueMaxValue 属性指示的范围。

注释

因为 BigInteger 类型是不可变的(请参阅可变性)并且没有上限或下限,所以任何导致 OutOfMemoryException 值变得过大的操作都可能引发 BigInteger

实例化 BigInteger 对象

可以通过多种方式实例化 BigInteger 对象:

  • 可以使用 new 关键字,并向构造函数提供任何整型或浮点值作为参数 BigInteger 。 (浮点值在分配给 BigInteger 之前被截断。)下面的示例演示如何使用 new 关键字实例化 BigInteger 值。

    BigInteger bigIntFromDouble = new BigInteger(179032.6541);
    Console.WriteLine(bigIntFromDouble);
    BigInteger bigIntFromInt64 = new BigInteger(934157136952);
    Console.WriteLine(bigIntFromInt64);
    // The example displays the following output:
    //   179032
    //   934157136952
    
    Dim bigIntFromDouble As New BigInteger(179032.6541)
    Console.WriteLine(bigIntFromDouble)
    Dim bigIntFromInt64 As New BigInteger(934157136952)
    Console.WriteLine(bigIntFromInt64)
    ' The example displays the following output:
    '   179032
    '   934157136952
    
  • 可以声明变量 BigInteger 并将其赋值,就像任何数值类型一样,只要该值是整型类型。 以下示例通过赋值从BigInteger创建Int64值。

    long longValue = 6315489358112;
    BigInteger assignedFromLong = longValue;
    Console.WriteLine(assignedFromLong);
    // The example displays the following output:
    //   6315489358112
    
    Dim longValue As Long = 6315489358112
    Dim assignedFromLong As BigInteger = longValue
    Console.WriteLine(assignedFromLong)
    ' The example displays the following output:
    '   6315489358112
    
  • 如果先对值进行强制转换或转换,就可以将小数或浮点值赋给 BigInteger 对象。 以下示例显式地将(C# 中的)DoubleDecimal 值转换为(Visual Basic 中的)BigInteger

    BigInteger assignedFromDouble = (BigInteger) 179032.6541;
    Console.WriteLine(assignedFromDouble);
    BigInteger assignedFromDecimal = (BigInteger) 64312.65m;
    Console.WriteLine(assignedFromDecimal);
    // The example displays the following output:
    //   179032
    //   64312
    
    Dim assignedFromDouble As BigInteger = CType(179032.6541, BigInteger)
    Console.WriteLine(assignedFromDouble)
    Dim assignedFromDecimal As BigInteger = CType(64312.65D, BigInteger)
    Console.WriteLine(assignedFromDecimal)
    ' The example displays the following output:
    '   179032
    '   64312
    

这些方法使你能够实例化 BigInteger 其值仅在现有数值类型之一范围内的对象。 可以实例化一个 BigInteger 对象,其值可以通过以下三种方式之一超过现有数值类型的范围:

  • 可以使用 new 关键字并向构造函数提供任何大小的 BigInteger.BigInteger 字节数组。 例如:

    byte[] byteArray = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
    BigInteger newBigInt = new BigInteger(byteArray);
    Console.WriteLine($"The value of newBigInt is {newBigInt} (or 0x{newBigInt:x}).");
    // The example displays the following output:
    //   The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a).
    
    Dim byteArray() As Byte = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
    Dim newBigInt As New BigInteger(byteArray)
    Console.WriteLine("The value of newBigInt is {0} (or 0x{0:x}).", newBigInt)
    ' The example displays the following output:
    '   The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a).
    
  • 可以调用 ParseTryParse 方法将数字的字符串表示形式转换为 a BigInteger. 例如:

    string positiveString = "91389681247993671255432112000000";
    string negativeString = "-90315837410896312071002088037140000";
    BigInteger posBigInt = 0;
    BigInteger negBigInt = 0;
    
    try {
       posBigInt = BigInteger.Parse(positiveString);
       Console.WriteLine(posBigInt);
    }
    catch (FormatException)
    {
       Console.WriteLine($"Unable to convert the string '{positiveString}' to a BigInteger value.");
    }
    
    if (BigInteger.TryParse(negativeString, out negBigInt))
      Console.WriteLine(negBigInt);
    else
       Console.WriteLine($"Unable to convert the string '{negativeString}' to a BigInteger value.");
    
    // The example displays the following output:
    //   9.1389681247993671255432112E+31
    //   -9.0315837410896312071002088037E+34
    
    Dim positiveString As String = "91389681247993671255432112000000"
    Dim negativeString As String = "-90315837410896312071002088037140000"
    Dim posBigInt As BigInteger = 0
    Dim negBigInt As BigInteger = 0
    
    Try
        posBigInt = BigInteger.Parse(positiveString)
        Console.WriteLine(posBigInt)
    Catch e As FormatException
        Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.",
                          positiveString)
    End Try
    
    If BigInteger.TryParse(negativeString, negBigInt) Then
        Console.WriteLine(negBigInt)
    Else
        Console.WriteLine("Unable to convert the string '{0}' to a BigInteger value.",
                           negativeString)
    End If
    ' The example displays the following output:
    '   9.1389681247993671255432112E+31
    '   -9.0315837410896312071002088037E+34
    
  • 可以调用 static 方法(在 Visual Basic 中的 SharedBigInteger),对数值表达式执行某些操作并返回计算 BigInteger 结果。 以下示例通过将 UInt64.MaxValue 立方并将结果赋值给 BigInteger 来实现这一功能。

    BigInteger number = BigInteger.Pow(UInt64.MaxValue, 3);
    Console.WriteLine(number);
    // The example displays the following output:
    //    6277101735386680762814942322444851025767571854389858533375
    
    Dim number As BigInteger = BigInteger.Pow(UInt64.MaxValue, 3)
    Console.WriteLine(number)
    ' The example displays the following output:
    ' 6277101735386680762814942322444851025767571854389858533375
    

未初始化的BigInteger的值是Zero.

对 BigInteger 值执行操作

可以使用 BigInteger 实例,就像使用任何其他整型类型一样。 BigInteger 重载标准数值运算符,使你能够执行基本的数学运算,例如加法、减法、除法、乘法和一元求反。 还可以使用标准数值运算符来比较两 BigInteger 个值。 与其他整数类型一样,BigInteger 也支持按位 AndOrXOr、左移和右移运算符。 对于不支持自定义运算符的语言,该 BigInteger 结构还提供用于执行数学运算的等效方法。 这些包括AddDivideMultiplyNegateSubtract及其他几个项目。

结构中的 BigInteger 许多成员直接对应于其他整型类型的成员。 此外, BigInteger 添加如下成员:

许多这些附加成员对应于Math类的成员,该类提供了处理基元数值类型的功能。

可变性

以下示例实例化一个 BigInteger 对象,然后将其值递增一个。

BigInteger number = BigInteger.Multiply(Int64.MaxValue, 3);
number++;
Console.WriteLine(number);
Dim number As BigInteger = BigInteger.Multiply(Int64.MaxValue, 3)
number += 1
Console.WriteLine(number)

尽管此示例似乎修改现有对象的值,但情况并非如此。 BigInteger 对象是不可变的,这意味着在内部,公共语言运行时实际上会创建一个新 BigInteger 对象,并为其分配一个大于其先前值的值。 然后,此新对象将返回到调用方。

注释

.NET 中的其他数值类型也是不可变的。 但是,由于 BigInteger 该类型没有上限或下限,因此其值可能会增长非常大,并且会对性能产生可衡量的影响。

尽管此过程对调用方是透明的,但它确实会产生性能损失。 在某些情况下,尤其是在循环中对非常大的BigInteger值执行重复操作时,可能会导致显著的性能损失。 例如,在下面的示例中,一个操作会重复执行达一百万次,每次操作成功后,BigInteger 值都会递增一。

BigInteger number = Int64.MaxValue ^ 5;
int repetitions = 1000000;
// Perform some repetitive operation 1 million times.
for (int ctr = 0; ctr <= repetitions; ctr++)
{
    // Perform some operation. If it fails, exit the loop.
    if (!SomeOperationSucceeds()) break;
    // The following code executes if the operation succeeds.
    number++;
}
Dim number As BigInteger = Int64.MaxValue ^ 5
Dim repetitions As Integer = 1000000
' Perform some repetitive operation 1 million times.
For ctr As Integer = 0 To repetitions
    ' Perform some operation. If it fails, exit the loop.
    If Not SomeOperationSucceeds() Then Exit For
    ' The following code executes if the operation succeeds.
    number += 1
Next

在这种情况下,可以通过对变量执行所有中间赋值 Int32 来提高性能。 然后,变量的最终值可以在循环退出时分配给 BigInteger 对象。 下面的示例进行了这方面的演示。

BigInteger number = Int64.MaxValue ^ 5;
int repetitions = 1000000;
int actualRepetitions = 0;
// Perform some repetitive operation 1 million times.
for (int ctr = 0; ctr <= repetitions; ctr++)
{
    // Perform some operation. If it fails, exit the loop.
    if (!SomeOperationSucceeds()) break;
    // The following code executes if the operation succeeds.
    actualRepetitions++;
}
number += actualRepetitions;
Dim number As BigInteger = Int64.MaxValue ^ 5
Dim repetitions As Integer = 1000000
Dim actualRepetitions As Integer = 0
' Perform some repetitive operation 1 million times.
For ctr As Integer = 0 To repetitions
    ' Perform some operation. If it fails, exit the loop.
    If Not SomeOperationSucceeds() Then Exit For
    ' The following code executes if the operation succeeds.
    actualRepetitions += 1
Next
number += actualRepetitions

字节数组和十六进制字符串

如果将值转换为 BigInteger 字节数组,或者将字节数组转换为 BigInteger 值,则必须考虑字节的顺序。 该 BigInteger 结构要求字节数组中的单个字节以小字节顺序显示(也就是说,该值的下序字节位于高阶字节之前)。 可以通过调用BigInteger该方法,然后将生成的字节数组传递给ToByteArray构造函数来往返BigInteger(Byte[])值,如以下示例所示。

BigInteger number = BigInteger.Pow(Int64.MaxValue, 2);
Console.WriteLine(number);

// Write the BigInteger value to a byte array.
byte[] bytes = number.ToByteArray();

// Display the byte array.
foreach (byte byteValue in bytes)
    Console.Write("0x{0:X2} ", byteValue);
Console.WriteLine();

// Restore the BigInteger value from a Byte array.
BigInteger newNumber = new BigInteger(bytes);
Console.WriteLine(newNumber);
// The example displays the following output:
//    8.5070591730234615847396907784E+37
//    0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x3F
//
//    8.5070591730234615847396907784E+37
Dim number As BigInteger = BigInteger.Pow(Int64.MaxValue, 2)     
Console.WriteLine(number)

' Write the BigInteger value to a byte array.
Dim bytes() As Byte = number.ToByteArray()

' Display the byte array.
For Each byteValue As Byte In bytes
   Console.Write("0x{0:X2} ", byteValue)
Next   
Console.WriteLine()

' Restore the BigInteger value from a Byte array.
Dim newNumber As BigInteger = New BigInteger(bytes)
Console.WriteLine(newNumber)               
' The example displays the following output:
'    8.5070591730234615847396907784E+37
'    0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x3F
'    
'    8.5070591730234615847396907784E+37

若要实例化 BigInteger 表示其他一些整型类型的值的字节数组中的值,可以将整型值 BitConverter.GetBytes 传递给方法,然后将生成的字节数组传递给 BigInteger(Byte[]) 构造函数。 以下示例实例化一个 BigInteger 值,来自表示 Int16 值的字节数组。

short originalValue = 30000;
Console.WriteLine(originalValue);

// Convert the Int16 value to a byte array.
byte[] bytes = BitConverter.GetBytes(originalValue);

// Display the byte array.
foreach (byte byteValue in bytes)
    Console.Write("0x{0} ", byteValue.ToString("X2"));
Console.WriteLine();

// Pass byte array to the BigInteger constructor.
BigInteger number = new BigInteger(bytes);
Console.WriteLine(number);
// The example displays the following output:
//       30000
//       0x30 0x75
//       30000
Dim originalValue As Short = 30000
Console.WriteLine(originalValue)

' Convert the Int16 value to a byte array.
Dim bytes() As Byte = BitConverter.GetBytes(originalValue)

' Display the byte array.
For Each byteValue As Byte In bytes
   Console.Write("0x{0} ", byteValue.ToString("X2"))
Next    
Console.WriteLine() 

' Pass byte array to the BigInteger constructor.
Dim number As BigInteger = New BigInteger(bytes)
Console.WriteLine(number)
' The example displays the following output:
'       30000
'       0x30 0x75
'       30000

BigInteger 结构假定负值使用二进制补码表示来存储。 BigInteger由于结构表示没有固定长度的数值,BigInteger(Byte[])因此构造函数始终将数组中最后一个字节的最有效位解释为符号位。 为防止 BigInteger(Byte[]) 构造函数将负值的二进制补码表示与正值的符号和大小表示相混淆,如果字节数组中最后一个字节的最重要位通常被置位,则正值应包括一个额外的字节,其值为 0。 例如,0xC0 0xBD 0xF0 0xFF是 -1,000,000 或 4,293,967,296 的小数十六进制表示形式。 因为此数组中最后一个字节的最高有效位处于打开状态,所以 BigInteger(Byte[]) 构造函数会将字节数组的值解释为 -1,000,000。 若要实例化 BigInteger 其值为正的字节数组,必须将其元素0xC0 0xBD 0xF0 0xFF 0x00的字节数组传递给构造函数。 以下示例对此进行了说明。

int negativeNumber = -1000000;
uint positiveNumber = 4293967296;

byte[] negativeBytes = BitConverter.GetBytes(negativeNumber);
BigInteger negativeBigInt = new BigInteger(negativeBytes);
Console.WriteLine(negativeBigInt.ToString("N0"));

byte[] tempPosBytes = BitConverter.GetBytes(positiveNumber);
byte[] positiveBytes = new byte[tempPosBytes.Length + 1];
Array.Copy(tempPosBytes, positiveBytes, tempPosBytes.Length);
BigInteger positiveBigInt = new BigInteger(positiveBytes);
Console.WriteLine(positiveBigInt.ToString("N0"));
// The example displays the following output:
//    -1,000,000
//    4,293,967,296
Dim negativeNumber As Integer = -1000000
Dim positiveNumber As UInteger = 4293967296

Dim negativeBytes() As Byte = BitConverter.GetBytes(negativeNumber) 
Dim negativeBigInt As New BigInteger(negativeBytes)
Console.WriteLine(negativeBigInt.ToString("N0"))

Dim tempPosBytes() As Byte = BitConverter.GetBytes(positiveNumber)
Dim positiveBytes(tempposBytes.Length) As Byte
Array.Copy(tempPosBytes, positiveBytes, tempPosBytes.Length)
Dim positiveBigInt As New BigInteger(positiveBytes)
Console.WriteLine(positiveBigInt.ToString("N0")) 
' The example displays the following output:
'    -1,000,000
'    4,293,967,296

ToByteArray 正值方法创建的字节数组包括此额外的零值字节。 因此,BigInteger 结构可以通过将值分配给字节数组,然后从字节数组中还原它们,从而成功实现值的往返转换,如以下示例所示。

BigInteger positiveValue = 15777216;
BigInteger negativeValue = -1000000;

Console.WriteLine("Positive value: " + positiveValue.ToString("N0"));
byte[] bytes = positiveValue.ToByteArray();

foreach (byte byteValue in bytes)
    Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
positiveValue = new BigInteger(bytes);
Console.WriteLine("Restored positive value: " + positiveValue.ToString("N0"));

Console.WriteLine();

Console.WriteLine("Negative value: " + negativeValue.ToString("N0"));
bytes = negativeValue.ToByteArray();
foreach (byte byteValue in bytes)
    Console.Write("{0:X2} ", byteValue);
Console.WriteLine();
negativeValue = new BigInteger(bytes);
Console.WriteLine("Restored negative value: " + negativeValue.ToString("N0"));
// The example displays the following output:
//       Positive value: 15,777,216
//       C0 BD F0 00
//       Restored positive value: 15,777,216
//
//       Negative value: -1,000,000
//       C0 BD F0
//       Restored negative value: -1,000,000
Dim positiveValue As BigInteger = 15777216
Dim negativeValue As BigInteger = -1000000

Console.WriteLine("Positive value: " + positiveValue.ToString("N0"))
Dim bytes() As Byte = positiveValue.ToByteArray()
For Each byteValue As Byte In bytes
   Console.Write("{0:X2} ", byteValue)
Next
Console.WriteLine()
positiveValue = New BigInteger(bytes)
Console.WriteLine("Restored positive value: " + positiveValue.ToString("N0"))

Console.WriteLine()
   
Console.WriteLIne("Negative value: " + negativeValue.ToString("N0"))
bytes = negativeValue.ToByteArray()
For Each byteValue As Byte In bytes
   Console.Write("{0:X2} ", byteValue)
Next
Console.WriteLine()
negativeValue = New BigInteger(bytes)
Console.WriteLine("Restored negative value: " + negativeValue.ToString("N0"))
' The example displays the following output:
'       Positive value: 15,777,216
'       C0 BD F0 00
'       Restored positive value: 15,777,216
'       
'       Negative value: -1,000,000
'       C0 BD F0
'       Restored negative value: -1,000,000

然而,您可能需要将这个零值字节额外添加到由开发人员动态生成的字节数组中,或者添加到使用将无符号整数转换为字节数组的方法返回的字节数组中(例如BitConverter.GetBytes(UInt16)BitConverter.GetBytes(UInt32)BitConverter.GetBytes(UInt64))。

解析十六进制字符串时,BigInteger.Parse(String, NumberStyles)BigInteger.Parse(String, NumberStyles, IFormatProvider) 方法假定如果字符串中第一个字节的最高有效位被设置,或者字符串的第一个十六进制数字表示字节值的低四位,则使用二进制补码表示法来表示该值。 例如,“FF01”和“F01”都表示十进制值 -255。 若要将正值与负值区分开来,正值应包括前导零。 ToString 方法的相关重载在传递“X”格式字符串时,会在返回的十六进制字符串中为正值添加前导零。 这使得可以使用 BigIntegerToString 方法往返 Parse 值,如以下示例所示。

BigInteger negativeNumber = -1000000;
BigInteger positiveNumber = 15777216;

string negativeHex = negativeNumber.ToString("X");
string positiveHex = positiveNumber.ToString("X");

BigInteger negativeNumber2, positiveNumber2;
negativeNumber2 = BigInteger.Parse(negativeHex,
                                   NumberStyles.HexNumber);
positiveNumber2 = BigInteger.Parse(positiveHex,
                                   NumberStyles.HexNumber);

Console.WriteLine($"Converted {negativeNumber:N0} to {negativeHex} back to {negativeNumber2:N0}.");
Console.WriteLine($"Converted {positiveNumber:N0} to {positiveHex} back to {positiveNumber2:N0}.");
// The example displays the following output:
//       Converted -1,000,000 to F0BDC0 back to -1,000,000.
//       Converted 15,777,216 to 0F0BDC0 back to 15,777,216.
Dim negativeNumber As BigInteger = -1000000
Dim positiveNumber As BigInteger = 15777216

Dim negativeHex As String = negativeNumber.ToString("X")
Dim positiveHex As string = positiveNumber.ToString("X")

Dim negativeNumber2, positiveNumber2 As BigInteger 
negativeNumber2 = BigInteger.Parse(negativeHex, 
                                   NumberStyles.HexNumber)
positiveNumber2 = BigInteger.Parse(positiveHex,
                                   NumberStyles.HexNumber)

Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.", 
                   negativeNumber, negativeHex, negativeNumber2)                                         
Console.WriteLine("Converted {0:N0} to {1} back to {2:N0}.", 
                   positiveNumber, positiveHex, positiveNumber2)                                         
' The example displays the following output:
'       Converted -1,000,000 to F0BDC0 back to -1,000,000.
'       Converted 15,777,216 to 0F0BDC0 back to 15,777,216.

但是,通过调用其他整型类型的ToString方法或包含ToString参数的toBase方法重载创建的十六进制字符串,并不表示值的符号或派生该十六进制字符串的源数据类型。 成功实例化 BigInteger 此类字符串中的值需要一些额外的逻辑。 以下示例提供了一个可能的实现。

using System;
using System.Globalization;
using System.Numerics;

public struct HexValue
{
    public int Sign;
    public string Value;
}

public class ByteHexExample2
{
    public static void Main()
    {
        uint positiveNumber = 4039543321;
        int negativeNumber = -255423975;

        // Convert the numbers to hex strings.
        HexValue hexValue1, hexValue2;
        hexValue1.Value = positiveNumber.ToString("X");
        hexValue1.Sign = Math.Sign(positiveNumber);

        hexValue2.Value = Convert.ToString(negativeNumber, 16);
        hexValue2.Sign = Math.Sign(negativeNumber);

        // Round-trip the hexadecimal values to BigInteger values.
        string hexString;
        BigInteger positiveBigInt, negativeBigInt;

        hexString = (hexValue1.Sign == 1 ? "0" : "") + hexValue1.Value;
        positiveBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber);
        Console.WriteLine($"Converted {positiveNumber} to {hexValue1.Value} and back to {positiveBigInt}.");

        hexString = (hexValue2.Sign == 1 ? "0" : "") + hexValue2.Value;
        negativeBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber);
        Console.WriteLine($"Converted {negativeNumber} to {hexValue2.Value} and back to {negativeBigInt}.");
    }
}
// The example displays the following output:
//       Converted 4039543321 to F0C68A19 and back to 4039543321.
//       Converted -255423975 to f0c68a19 and back to -255423975.
Imports System.Globalization
Imports System.Numerics

Public Structure HexValue
    Public Sign As Integer
    Public Value As String
End Structure

Module Example2
    Public Sub Main()
        Dim positiveNumber As UInteger = 4039543321
        Dim negativeNumber As Integer = -255423975

        ' Convert the numbers to hex strings.
        Dim hexValue1, hexValue2 As HexValue
        hexValue1.Value = positiveNumber.ToString("X")
        hexValue1.Sign = Math.Sign(positiveNumber)

        hexValue2.Value = Convert.ToString(negativeNumber, 16)
        hexValue2.Sign = Math.Sign(negativeNumber)

        ' Round-trip the hexadecimal values to BigInteger values.
        Dim hexString As String
        Dim positiveBigInt, negativeBigInt As BigInteger

        hexString = CStr(IIf(hexValue1.Sign = 1, "0", "")) + hexValue1.Value
        positiveBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber)
        Console.WriteLine("Converted {0} to {1} and back to {2}.",
                        positiveNumber, hexValue1.Value, positiveBigInt)

        hexString = CStr(IIf(hexValue2.Sign = 1, "0", "")) + hexValue2.Value
        negativeBigInt = BigInteger.Parse(hexString, NumberStyles.HexNumber)
        Console.WriteLine("Converted {0} to {1} and back to {2}.",
                        negativeNumber, hexValue2.Value, negativeBigInt)

    End Sub
End Module
' The example displays the following output:
'       Converted 4039543321 to F0C68A19 and back to 4039543321.
'       Converted -255423975 to f0c68a19 and back to -255423975.

构造函数

名称 说明
BigInteger(Byte[])

使用字节数组中的值初始化结构的新实例 BigInteger

BigInteger(Decimal)

使用BigInteger值初始化结构的新实例Decimal

BigInteger(Double)

使用双精度浮点值初始化结构的新实例 BigInteger

BigInteger(Int32)

使用 32 位有符号整数值初始化结构的新实例 BigInteger

BigInteger(Int64)

使用 64 位带符号整数值初始化结构的新实例 BigInteger

BigInteger(ReadOnlySpan<Byte>, Boolean, Boolean)

使用只读字节范围中的值初始化结构的新实例 BigInteger ,并选择性地指示签名编码和字节字节顺序。

BigInteger(Single)

使用单精度浮点值初始化结构的新实例 BigInteger

BigInteger(UInt32)

使用无符号 32 位整数值初始化结构的新实例 BigInteger

BigInteger(UInt64)

使用无符号 64 位整数值初始化结构的新实例 BigInteger

属性

名称 说明
IsEven

指示当前 BigInteger 对象的值是否为偶数。

IsOne

指示当前 BigInteger 对象的值是否为 One

IsPowerOfTwo

指示当前 BigInteger 对象的值是否为 2 的幂。

IsZero

指示当前 BigInteger 对象的值是否为 Zero

MinusOne

获取一个值,该值表示数字负一(-1)。

One

获取一个值,该值表示第一个 (1)。

Sign

获取一个数字,该值指示当前 BigInteger 对象的符号(负数、正数或零)。

Zero

获取一个值,该值表示数字 0(零)。

方法

名称 说明
Abs(BigInteger)

获取对象的绝对值 BigInteger

Add(BigInteger, BigInteger)

添加两个 BigInteger 值并返回结果。

Clamp(BigInteger, BigInteger, BigInteger)

将值固定到非独占最小值和最大值。

Compare(BigInteger, BigInteger)

比较两 BigInteger 个值并返回一个整数,该值指示第一个值是小于、等于还是大于第二个值。

CompareTo(BigInteger)

将此实例与第二 BigInteger 个实例进行比较,并返回一个整数,该值指示此实例的值是小于、等于还是大于指定对象的值。

CompareTo(Int64)

将此实例与有符号的 64 位整数进行比较,并返回一个整数,该值指示此实例的值是小于、等于还是大于有符号 64 位整数的值。

CompareTo(Object)

将此实例与指定的对象进行比较,并返回一个整数,该整数指示此实例的值是小于、等于还是大于指定对象的值。

CompareTo(UInt64)

将此实例与无符号 64 位整数进行比较,并返回一个整数,该值指示此实例的值是小于、等于还是大于无符号 64 位整数的值。

CopySign(BigInteger, BigInteger)

将值的符号复制到另一个值的符号。

CreateChecked<TOther>(TOther)

从值创建当前类型的实例,为超出当前类型的可表示范围的任何值引发溢出异常。

CreateSaturating<TOther>(TOther)

从值创建当前类型的实例,使属于当前类型的可表示范围之外的任何值饱和。

CreateTruncating<TOther>(TOther)

从值创建当前类型的实例,截断属于当前类型的可表示范围之外的任何值。

Divide(BigInteger, BigInteger)

将一个值除以另一个 BigInteger 值并返回结果。

DivRem(BigInteger, BigInteger, BigInteger)

将一个值除以另一个 BigInteger 值,返回结果,并在输出参数中返回余数。

DivRem(BigInteger, BigInteger)

计算两个值的商和余数。

Equals(BigInteger)

返回一个值,该值指示当前实例和指定 BigInteger 对象是否具有相同的值。

Equals(Int64)

返回一个值,该值指示当前实例和有符号的 64 位整数是否具有相同的值。

Equals(Object)

返回一个值,该值指示当前实例和指定对象是否具有相同的值。

Equals(UInt64)

返回一个值,该值指示当前实例和无符号 64 位整数是否具有相同的值。

GetBitLength()

获取最短两个实例的补全表示形式所需的位数,而无需符号位。

GetByteCount(Boolean)

获取要输出的 ToByteArray(Boolean, Boolean) 字节数和 TryWriteBytes(Span<Byte>, Int32, Boolean, Boolean)

GetHashCode()

返回当前 BigInteger 对象的哈希代码。

GreatestCommonDivisor(BigInteger, BigInteger)

查找两 BigInteger 个值的最大常见除数。

IsEvenInteger(BigInteger)

确定值是否表示偶数。

IsNegative(BigInteger)

确定值是否为负值。

IsOddInteger(BigInteger)

确定值是否表示奇数整数。

IsPositive(BigInteger)

确定值是否为正值。

IsPow2(BigInteger)

确定值是否为 2 的幂。

LeadingZeroCount(BigInteger)

计算值中的前导零数。

Log(BigInteger, Double)

返回指定基数中指定数字的对数。

Log(BigInteger)

返回指定数字的自然 (base e) 对数。

Log10(BigInteger)

返回指定数字的基数 10 对数。

Log2(BigInteger)

计算值的 log2。

Max(BigInteger, BigInteger)

返回两 BigInteger 个值中的较大值。

MaxMagnitude(BigInteger, BigInteger)

比较两个值与计算值更大。

Min(BigInteger, BigInteger)

返回两 BigInteger 个值中的较小值。

MinMagnitude(BigInteger, BigInteger)

比较两个值与计算值较小。

ModPow(BigInteger, BigInteger, BigInteger)

对提升为另一个数字幂的数字执行取模除法。

Multiply(BigInteger, BigInteger)

返回两 BigInteger 个值的乘积。

Negate(BigInteger)

否定指定 BigInteger 值。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

表示任意大有符号整数。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

表示任意大有符号整数。

Parse(ReadOnlySpan<Char>, IFormatProvider)

将字符的范围分析为值。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

将指定样式中的指定只读字符范围中包含的数字的表示形式转换为等效 BigInteger 的字符。

Parse(String, IFormatProvider)

将指定区域性特定格式的数字的字符串表示形式转换为其 BigInteger 等效格式。

Parse(String, NumberStyles, IFormatProvider)

将指定样式和区域性特定格式的数字的字符串表示形式转换为其 BigInteger 等效格式。

Parse(String, NumberStyles)

将指定样式中的数字的字符串表示形式转换为其 BigInteger 等效形式。

Parse(String)

将数字的字符串表示形式转换为其 BigInteger 等效形式。

PopCount(BigInteger)

计算值中设置的位数。

Pow(BigInteger, Int32)

将值 BigInteger 提升为指定值的幂。

Remainder(BigInteger, BigInteger)

对两 BigInteger 个值执行整数除法并返回余数。

RotateLeft(BigInteger, Int32)

按给定量旋转一个值。

RotateRight(BigInteger, Int32)

按给定的量向右旋转值。

Subtract(BigInteger, BigInteger)

从另一个值中减去一个 BigInteger 值并返回结果。

ToByteArray()

将值 BigInteger 转换为字节数组。

ToByteArray(Boolean, Boolean)

使用尽可能少的字节数返回作为 BigInteger 字节数组的值。 如果值为零,则返回其元素0x00的一个字节的数组。

ToString()

将当前 BigInteger 对象的数值转换为其等效的字符串表示形式。

ToString(IFormatProvider)

使用指定的区域性特定格式设置信息将当前 BigInteger 对象的数值转换为其等效的字符串表示形式。

ToString(String, IFormatProvider)

使用指定的格式和区域性特定的格式信息,将当前 BigInteger 对象的数值转换为其等效的字符串表示形式。

ToString(String)

使用指定的格式将当前 BigInteger 对象的数值转换为其等效的字符串表示形式。

TrailingZeroCount(BigInteger)

计算值中的尾随零数。

TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

表示任意大有符号整数。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

将此大整数实例的格式设置为字符范围。

TryParse(ReadOnlySpan<Byte>, BigInteger)

表示任意大有符号整数。

TryParse(ReadOnlySpan<Byte>, IFormatProvider, BigInteger)

表示任意大有符号整数。

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, BigInteger)

表示任意大有符号整数。

TryParse(ReadOnlySpan<Char>, BigInteger)

尝试将指定只读字符范围中包含的数字的表示形式转换为等效 BigInteger 字符,并返回一个值,该值指示转换是否成功。

TryParse(ReadOnlySpan<Char>, IFormatProvider, BigInteger)

尝试将字符范围分析为值。

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, BigInteger)

尝试将数字的字符串表示形式转换为等效 BigInteger 项,并返回一个值,该值指示转换是否成功。

TryParse(String, BigInteger)

尝试将数字的字符串表示形式转换为等效 BigInteger 项,并返回一个值,该值指示转换是否成功。

TryParse(String, IFormatProvider, BigInteger)

尝试将字符串分析为值。

TryParse(String, NumberStyles, IFormatProvider, BigInteger)

尝试将指定样式和区域性特定格式的数字的字符串表示形式转换为其 BigInteger 等效格式,并返回一个值,该值指示转换是否成功。

TryWriteBytes(Span<Byte>, Int32, Boolean, Boolean)

使用尽可能少的字节数,将此值 BigInteger 复制为小尾双补字节。 如果值为零,则输出其元素0x00的一个字节。

运营商

名称 说明
Addition(BigInteger, BigInteger)

添加两个指定 BigInteger 对象的值。

BitwiseAnd(BigInteger, BigInteger)

对两And个值执行按BigInteger位运算。

BitwiseOr(BigInteger, BigInteger)

对两Or个值执行按BigInteger位运算。

Decrement(BigInteger)

BigInteger将值递减 1。

Division(BigInteger, BigInteger)

使用整数除法将指定 BigInteger 值除以另一个指定 BigInteger 值。

Equality(BigInteger, BigInteger)

返回一个值,该值指示两 BigInteger 个对象的值是否相等。

Equality(BigInteger, Int64)

返回一个值,该值指示值 BigInteger 和带符号长整数值是否相等。

Equality(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 和无符号长整数值是否相等。

Equality(Int64, BigInteger)

返回一个值,该值指示有符号长整数值和 BigInteger 值是否相等。

Equality(UInt64, BigInteger)

返回一个值,该值指示无符号长整数值和 BigInteger 值是否相等。

ExclusiveOr(BigInteger, BigInteger)

对两Or个值执行按位排他 XOrBigInteger) 运算。

Explicit(BFloat16 to BigInteger)

表示任意大有符号整数。

Explicit(BigInteger to BFloat16)

表示任意大有符号整数。

Explicit(BigInteger to Byte)

定义对象的显式转换为 BigInteger 无符号字节值。

Explicit(BigInteger to Char)

显式将大整数转换为 Char 值。

Explicit(BigInteger to Decimal)

定义对象的BigInteger显式转换为Decimal值。

Explicit(BigInteger to Double)

定义对象的BigInteger显式转换为Double值。

Explicit(BigInteger to Half)

显式将大整数转换为 Half 值。

Explicit(BigInteger to Int128)

显式将大整数转换为 Int128 值。

Explicit(BigInteger to Int16)

定义对象的显式转换为 BigInteger 16 位有符号整数值。

Explicit(BigInteger to Int32)

定义对象的显式转换为 BigInteger 32 位有符号整数值。

Explicit(BigInteger to Int64)

定义对象的显式转换为 BigInteger 64 位有符号整数值。

Explicit(BigInteger to IntPtr)

显式将大整数转换为 IntPtr 值。

Explicit(BigInteger to SByte)

定义对象的显式转换 BigInteger 到有符号的 8 位值。

此 API 不符合 CLS。 合规的替代项是 Int16

Explicit(BigInteger to Single)

定义对象的显式转换为 BigInteger 单精度浮点值。

Explicit(BigInteger to UInt128)

显式将大整数转换为 UInt128 值。

Explicit(BigInteger to UInt16)

定义对象的显式转换 BigInteger 到无符号 16 位整数值。

此 API 不符合 CLS。 合规的替代项是 Int32

Explicit(BigInteger to UInt32)

定义对象的显式转换 BigInteger 到无符号 32 位整数值。

此 API 不符合 CLS。 合规的替代项是 Int64

Explicit(BigInteger to UInt64)

定义对象的显式转换为 BigInteger 无符号 64 位整数值。

此 API 不符合 CLS。 合规的替代项是 Double

Explicit(BigInteger to UIntPtr)

显式将大整数转换为 UIntPtr 值。

Explicit(Complex to BigInteger)

显式将值 Complex 转换为大整数。

Explicit(Decimal to BigInteger)

定义对象的Decimal显式转换为BigInteger值。

Explicit(Double to BigInteger)

定义值到值的Double显式转换BigInteger

Explicit(Half to BigInteger)

显式将值 Half 转换为大整数。

Explicit(Single to BigInteger)

定义值到值的Single显式转换BigInteger

GreaterThan(BigInteger, BigInteger)

返回一个值,该值指示值 BigInteger 是否大于另一个 BigInteger 值。

GreaterThan(BigInteger, Int64)

返回一个值,该值指示一个 BigInteger 是否大于 64 位有符号整数值。

GreaterThan(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 是否大于 64 位无符号整数。

GreaterThan(Int64, BigInteger)

返回一个值,该值指示 64 位有符号整数是否大于 BigInteger 值。

GreaterThan(UInt64, BigInteger)

返回一个值,该值指示值 BigInteger 是否大于 64 位无符号整数。

GreaterThanOrEqual(BigInteger, BigInteger)

返回一个值,该值指示值 BigInteger 是否大于或等于另一个 BigInteger 值。

GreaterThanOrEqual(BigInteger, Int64)

返回一个值,该值指示值 BigInteger 是否大于或等于 64 位有符号整数值。

GreaterThanOrEqual(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 是否大于或等于 64 位无符号整数值。

GreaterThanOrEqual(Int64, BigInteger)

返回一个值,该值指示 64 位有符号整数是否大于或等于值 BigInteger

GreaterThanOrEqual(UInt64, BigInteger)

返回一个值,该值指示 64 位无符号整数是否大于或等于值 BigInteger

Implicit(Byte to BigInteger)

定义将无符号字节隐式转换为值 BigInteger

Implicit(Char to BigInteger)

隐式将值 Char 转换为大整数。

Implicit(Int128 to BigInteger)

隐式将值 Int128 转换为大整数。

Implicit(Int16 to BigInteger)

定义有符号 16 位整数到值的 BigInteger 隐式转换。

Implicit(Int32 to BigInteger)

定义有符号 32 位整数到值的 BigInteger 隐式转换。

Implicit(Int64 to BigInteger)

定义有符号 64 位整数到值的 BigInteger 隐式转换。

Implicit(IntPtr to BigInteger)

隐式将值 IntPtr 转换为大整数。

Implicit(SByte to BigInteger)

定义 8 位有符号整数到值的 BigInteger 隐式转换。

此 API 不符合 CLS。 合规的替代项是 BigInteger(Int32)

Implicit(UInt128 to BigInteger)

隐式将值 UInt128 转换为大整数。

Implicit(UInt16 to BigInteger)

定义 16 位无符号整数到值的 BigInteger 隐式转换。

此 API 不符合 CLS。 合规的替代项是 Implicit(Int32 to BigInteger)

Implicit(UInt32 to BigInteger)

定义 32 位无符号整数到值的 BigInteger 隐式转换。

此 API 不符合 CLS。 合规的替代项是 Implicit(Int64 to BigInteger)

Implicit(UInt64 to BigInteger)

定义 64 位无符号整数到值的 BigInteger 隐式转换。

此 API 不符合 CLS。 合规的替代项是 Double

Implicit(UIntPtr to BigInteger)

隐式将值 UIntPtr 转换为大整数。

Increment(BigInteger)

将值 BigInteger 递增 1。

Inequality(BigInteger, BigInteger)

返回一个值,该值指示两 BigInteger 个对象是否具有不同的值。

Inequality(BigInteger, Int64)

返回一个值,该值指示值 BigInteger 和 64 位有符号整数是否不相等。

Inequality(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 和 64 位无符号整数是否不相等。

Inequality(Int64, BigInteger)

返回一个值,该值指示 64 位有符号整数和值 BigInteger 是否不相等。

Inequality(UInt64, BigInteger)

返回一个值,该值指示 64 位无符号整数和 BigInteger 值是否不相等。

LeftShift(BigInteger, Int32)

将值 BigInteger 向左移动指定位数。

LessThan(BigInteger, BigInteger)

返回一个值,该值指示值 BigInteger 是否小于另一个 BigInteger 值。

LessThan(BigInteger, Int64)

返回一个值,该值指示值 BigInteger 是否小于 64 位有符号整数。

LessThan(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 是否小于 64 位无符号整数。

LessThan(Int64, BigInteger)

返回一个值,该值指示 64 位有符号整数是否小于值 BigInteger

LessThan(UInt64, BigInteger)

返回一个值,该值指示 64 位无符号整数是否小于值 BigInteger

LessThanOrEqual(BigInteger, BigInteger)

返回一个值,该值指示值 BigInteger 是否小于或等于另一个 BigInteger 值。

LessThanOrEqual(BigInteger, Int64)

返回一个值,该值指示值 BigInteger 是否小于或等于 64 位有符号整数。

LessThanOrEqual(BigInteger, UInt64)

返回一个值,该值指示值 BigInteger 是否小于或等于 64 位无符号整数。

LessThanOrEqual(Int64, BigInteger)

返回一个值,该值指示 64 位有符号整数是否小于或等于值 BigInteger

LessThanOrEqual(UInt64, BigInteger)

返回一个值,该值指示 64 位无符号整数是否小于或等于值 BigInteger

Modulus(BigInteger, BigInteger)

返回除法结果与两个指定 BigInteger 值的余数。

Multiply(BigInteger, BigInteger)

将两个指定 BigInteger 值相乘。

OnesComplement(BigInteger)

返回值的按位补数 BigInteger

RightShift(BigInteger, Int32)

将值 BigInteger 向右移动指定的位数。

Subtraction(BigInteger, BigInteger)

从另一个BigInteger值中减去值BigInteger

UnaryNegation(BigInteger)

否定指定的 BigInteger 值。

UnaryPlus(BigInteger)

返回操作数的值 BigInteger 。 (操作数的符号不变。

UnsignedRightShift(BigInteger, Int32)

将值右移一个给定的量。

显式接口实现

名称 说明
IAdditiveIdentity<BigInteger,BigInteger>.AdditiveIdentity

获取当前类型的累加标识。

IBinaryInteger<BigInteger>.GetByteCount()

获取将作为其一部分 TryWriteLittleEndian(Span<Byte>, Int32)写入的字节数。

IBinaryInteger<BigInteger>.GetShortestBitLength()

获取最短的两个当前值的补数表示形式的长度(以位为单位)。

IBinaryInteger<BigInteger>.Log10(BigInteger)

表示任意大有符号整数。

IBinaryInteger<BigInteger>.TryReadBigEndian(ReadOnlySpan<Byte>, Boolean, BigInteger)

表示任意大有符号整数。

IBinaryInteger<BigInteger>.TryReadLittleEndian(ReadOnlySpan<Byte>, Boolean, BigInteger)

表示任意大有符号整数。

IBinaryInteger<BigInteger>.TryWriteBigEndian(Span<Byte>, Int32)

尝试将当前值(采用 big-endian 格式)写入给定范围。

IBinaryInteger<BigInteger>.TryWriteLittleEndian(Span<Byte>, Int32)

尝试将当前值(以小端格式)写入给定范围。

IBinaryNumber<BigInteger>.AllBitsSet

获取在其中设置所有位的二进制类型的实例。

IComparable.CompareTo(Object)

将此实例与指定的对象进行比较,并返回一个整数,该整数指示此实例的值是小于、等于还是大于指定对象的值。

IMultiplicativeIdentity<BigInteger,BigInteger>.MultiplicativeIdentity

获取当前类型的乘法标识。

INumber<BigInteger>.MaxNumber(BigInteger, BigInteger)

将两个值与计算进行比较,如果一个输入 NaN是,则返回另一个值。

INumber<BigInteger>.MinNumber(BigInteger, BigInteger)

将两个值与计算进行比较,如果一个输入 NaN较小,则返回另一个值。

INumber<BigInteger>.Sign(BigInteger)

计算值的符号。

INumberBase<BigInteger>.IsCanonical(BigInteger)

确定某个值是否在其规范表示形式中。

INumberBase<BigInteger>.IsComplexNumber(BigInteger)

确定值是否表示复数。

INumberBase<BigInteger>.IsFinite(BigInteger)

确定值是否有限。

INumberBase<BigInteger>.IsImaginaryNumber(BigInteger)

确定值是否表示纯虚数。

INumberBase<BigInteger>.IsInfinity(BigInteger)

确定值是否无限。

INumberBase<BigInteger>.IsInteger(BigInteger)

确定值是否表示整数。

INumberBase<BigInteger>.IsNaN(BigInteger)

确定值是否为 NaN。

INumberBase<BigInteger>.IsNegativeInfinity(BigInteger)

确定值是否为负无穷大。

INumberBase<BigInteger>.IsNormal(BigInteger)

确定值是否正常。

INumberBase<BigInteger>.IsPositiveInfinity(BigInteger)

确定值是否为正无穷大。

INumberBase<BigInteger>.IsRealNumber(BigInteger)

确定值是否表示实数。

INumberBase<BigInteger>.IsSubnormal(BigInteger)

确定某个值是否为非正常值。

INumberBase<BigInteger>.IsZero(BigInteger)

确定值是否为零。

INumberBase<BigInteger>.MaxMagnitudeNumber(BigInteger, BigInteger)

将两个值与具有更大数量级的计算进行比较,如果一个输入为 NaN,则返回另一个值。

INumberBase<BigInteger>.MinMagnitudeNumber(BigInteger, BigInteger)

将两个值与具有较小数量级的计算进行比较,如果一个输入为 NaN,则返回另一个值。

INumberBase<BigInteger>.MultiplyAddEstimate(BigInteger, BigInteger, BigInteger)

计算估计值 (left * right) + 。 addend

INumberBase<BigInteger>.Radix

获取类型的基数。

INumberBase<BigInteger>.TryConvertFromChecked<TOther>(TOther, BigInteger)

表示任意大有符号整数。

INumberBase<BigInteger>.TryConvertFromSaturating<TOther>(TOther, BigInteger)

表示任意大有符号整数。

INumberBase<BigInteger>.TryConvertFromTruncating<TOther>(TOther, BigInteger)

表示任意大有符号整数。

INumberBase<BigInteger>.TryConvertToChecked<TOther>(BigInteger, TOther)

尝试将当前类型的实例转换为另一种类型,为超出当前类型可表示范围的任何值引发溢出异常。

INumberBase<BigInteger>.TryConvertToSaturating<TOther>(BigInteger, TOther)

尝试将当前类型的实例转换为另一种类型,使超出当前类型的可表示范围的任何值饱和。

INumberBase<BigInteger>.TryConvertToTruncating<TOther>(BigInteger, TOther)

尝试将当前类型的实例转换为另一种类型,截断属于当前类型的可表示范围之外的任何值。

ISignedNumber<BigInteger>.NegativeOne

获取类型的值 -1

适用于