BigInteger Constructores

Definición

Inicializa una nueva instancia de la estructura BigInteger.

Sobrecargas

BigInteger(Byte[])

Inicializa una nueva instancia de la estructura BigInteger utilizando los valores de una matriz de bytes.

BigInteger(Decimal)

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor Decimal.

BigInteger(Double)

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor de punto flotante de precisión doble.

BigInteger(Int32)

Inicializa una nueva instancia de la estructura BigInteger usando un valor entero de 32 bits con signo.

BigInteger(Int64)

Inicializa una nueva instancia de la estructura BigInteger usando un valor entero de 64 bits con signo.

BigInteger(Single)

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor de punto flotante de precisión sencilla.

BigInteger(UInt32)

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor entero de 32 bits sin signo.

BigInteger(UInt64)

Inicializa una nueva instancia de la estructura BigInteger con un valor entero de 64 bits sin signo.

BigInteger(ReadOnlySpan<Byte>, Boolean, Boolean)

Inicializa una nueva instancia de la estructura BigInteger mediante los valores de un intervalo de solo lectura de bytes y, de forma opcional, indica la codificación de firma y el orden de bytes endianness.

BigInteger(Byte[])

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Esta API no es conforme a CLS.

Inicializa una nueva instancia de la estructura BigInteger utilizando los valores de una matriz de bytes.

public:
 BigInteger(cli::array <System::Byte> ^ value);
[System.CLSCompliant(false)]
public BigInteger (byte[] value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : byte[] -> System.Numerics.BigInteger
Public Sub New (value As Byte())

Parámetros

value
Byte[]

Matriz de valores de byte en orden little-endian.

Atributos

Excepciones

value es null.

Ejemplos

En el ejemplo siguiente se crea una instancia de un BigInteger objeto de una matriz de bytes de 5 elementos cuyo valor es {5, 4, 3, 2, 1}. A continuación, muestra el BigInteger valor, representado como números decimales y hexadecimales, en la consola. Una comparación de la matriz de entrada con la salida de texto deja claro por qué esta sobrecarga del constructor de BigInteger clase crea un BigInteger objeto cuyo valor es 4328719365 (o 0x102030405). El primer elemento de la matriz de bytes, cuyo valor es 5, define el valor del byte de orden inferior del BigInteger objeto, que es 0x05. El segundo elemento de la matriz de bytes, cuyo valor es 4, define el valor del segundo byte del BigInteger objeto, que es 0x04, etc.

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 example displays the following output:
//    The value of number is 4328719365 (or 0x102030405).
Dim bytes() As Byte = { 5, 4, 3, 2, 1 }
Dim number As New BigInteger(bytes)
Console.WriteLine("The value of number is {0} (or 0x{0:x}).", number) 
' The example displays the following output:
'    The value of number is 4328719365 (or 0x102030405).

En el ToByteArray ejemplo siguiente se crea una instancia de un valor positivo y negativoBigInteger, se pasan al método y, a continuación, se restauran los valores originales BigInteger de la matriz de bytes resultante. Tenga en cuenta que los dos valores se representan mediante matrices de bytes idénticas. La única diferencia entre ellos es en el bit más significativo del último elemento de la matriz de bytes. Este bit se establece (el valor del byte se 0xFF) si la matriz se crea a partir de un valor negativo BigInteger . El bit no se establece (el valor del byte es cero), si la matriz se crea a partir de un valor positivo BigInteger .

// 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();
// The example displays the following output:
//    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
' Instantiate BigInteger values.
Dim positiveValue As BigInteger = BigInteger.Parse("4713143110832790377889")
Dim negativeValue As BigInteger = BigInteger.Add(-Int64.MaxValue, -60000) 
Dim positiveValue2, negativeValue2 As BigInteger

' Create two byte arrays.
Dim positiveBytes() As Byte = positiveValue.ToByteArray()
Dim negativeBytes() As Byte = negativeValue.ToByteArray()

' Instantiate new BigInteger from negativeBytes array.
Console.Write("Converted {0:N0} to the byte array ", negativeValue)
For Each byteValue As Byte In negativeBytes
   Console.Write("{0:X2} ", byteValue)
Next 
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)
For Each byteValue As Byte In positiveBytes
   Console.Write("{0:X2} ", byteValue)
Next 
Console.WriteLine()
positiveValue2 = New BigInteger(positiveBytes)
Console.WriteLine("Converted the byte array to {0:N0}", positiveValue2)
Console.WriteLine()
' The example displays the following output:
'    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

En el ejemplo siguiente se muestra cómo asegurarse de que un valor positivo no se crea una instancia incorrecta como un valor negativo agregando un byte cuyo valor es cero al final de la matriz.

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);
// The example displays the following output:
//    Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.
Dim originalNumber As ULong = UInt64.MaxValue
' Convert an unsigned integer to a byte array.
Dim bytes() As Byte = BitConverter.GetBytes(originalNumber)
' Determine whether the MSB of the highest-order byte is set.
If originalNumber > 0 And (bytes(bytes.Length - 1) And &h80) > 0 Then
   ' If the MSB is set, add one zero-value byte to the end of the array.
   ReDim Preserve bytes(bytes.Length)
End If

Dim newNumber As New BigInteger(bytes)
Console.WriteLine("Converted the UInt64 value {0:N0} to {1:N0}.", 
                  originalNumber, newNumber) 
' The example displays the following output:
'    Converted the UInt64 value 18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.

Comentarios

Los bytes individuales de la value matriz deben estar en orden little-endian, de byte de orden inferior a byte de orden superior. Por ejemplo, el valor numérico 1000 000 000 000 000 000 se representa como se muestra en la tabla siguiente:

Cadena hexadecimal E8D4A51000
Matriz de bytes (índice más bajo primero) 00 10 A5 D4 E8 00

La mayoría de los métodos que convierten valores numéricos en matrices de bytes, como BigInteger.ToByteArray y BitConverter.GetBytes, devuelven matrices de bytes en orden little-endian.

El constructor espera valores positivos en la matriz de bytes para usar la representación de signo y magnitud, y los valores negativos para usar la representación complementaria de dos. En otras palabras, si se establece el bit de orden más alto del byte de orden superior de value , el valor resultante BigInteger es negativo. Dependiendo del origen de la matriz de bytes, esto puede hacer que un valor positivo se malinterprete como un valor negativo. Normalmente, las matrices de bytes se generan de las siguientes maneras:

  • Llamando al BigInteger.ToByteArray método . Dado que este método devuelve una matriz de bytes con el bit de orden más alto del byte de orden más alto de la matriz establecida en cero para los valores positivos, no hay ninguna posibilidad de malinterpretar un valor positivo como negativo. Las matrices de bytes sin modificar creadas por el ToByteArray método siempre realizan correctamente un recorrido de ida y vuelta cuando se pasan al BigInteger(Byte[]) constructor.

  • Al llamar al BitConverter.GetBytes método y pasarlo un entero con signo como parámetro. Dado que los enteros con signo controlan la representación de signo y magnitud y la representación complementaria de dos, no hay posibilidad de malinterpretar un valor positivo como negativo.

  • Al llamar al BitConverter.GetBytes método y pasarlo un entero sin signo como parámetro. Dado que los enteros sin signo solo se representan mediante su magnitud, los valores positivos se pueden interpretar erróneamente como valores negativos. Para evitar esta interpretación incorrecta, puede agregar un valor de cero byte al final de la matriz. En el ejemplo de la sección siguiente se proporciona una ilustración.

  • Mediante la creación de una matriz de bytes de forma dinámica o estática sin llamar necesariamente a ninguno de los métodos anteriores o modificando una matriz de bytes existente. Para evitar que los valores positivos se malinterpreten como valores negativos, puede agregar un valor de cero byte al final de la matriz.

Si value es una matriz vacía Byte , el nuevo BigInteger objeto se inicializa en un valor de BigInteger.Zero. Si value es null, el constructor produce un ArgumentNullException.

Consulte también

Se aplica a

BigInteger(Decimal)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor Decimal.

public:
 BigInteger(System::Decimal value);
public BigInteger (decimal value);
new System.Numerics.BigInteger : decimal -> System.Numerics.BigInteger
Public Sub New (value As Decimal)

Parámetros

value
Decimal

Número decimal.

Ejemplos

En el ejemplo siguiente se muestra el uso del BigInteger(Decimal) constructor para crear una instancia de un BigInteger objeto . Define una matriz de Decimal valores y, a continuación, pasa cada valor al BigInteger(Decimal) constructor. Tenga en cuenta que el Decimal valor se trunca en lugar de redondeado cuando se asigna al BigInteger objeto .

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);
}
// The example displays the following output:
//    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.
Dim decimalValues() As Decimal = { -1790.533d, -15.1514d, 18903.79d, 9180098.003d }
For Each decimalValue As Decimal In decimalValues
   Dim number As New BigInteger(decimalValue)
   Console.WriteLine("Instantiated BigInteger value {0} from the Decimal value {1}.",
                     number, decimalValue)
Next                 
' The example displays the following output:
'    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.

Comentarios

El resultado de llamar a este constructor es idéntico a asignar explícitamente un Decimal valor a una BigInteger variable.

Llamar a este constructor puede causar pérdida de datos; cualquier parte fraccionaria de se trunca al crear una instancia de value un BigInteger objeto.

Se aplica a

BigInteger(Double)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor de punto flotante de precisión doble.

public:
 BigInteger(double value);
public BigInteger (double value);
new System.Numerics.BigInteger : double -> System.Numerics.BigInteger
Public Sub New (value As Double)

Parámetros

value
Double

Valor de punto flotante de precisión doble.

Excepciones

Ejemplos

En el ejemplo siguiente se muestra el uso del BigInteger(Double) constructor para crear una instancia de un BigInteger objeto . También muestra la pérdida de precisión que puede producirse al usar el Double tipo de datos. Double Se asigna un valor grande, que luego se asigna a un BigInteger objeto . Como se muestra en la salida, esta asignación implica una pérdida de precisión. A continuación, ambos valores se incrementan en uno. La salida muestra que el BigInteger objeto refleja el valor cambiado, mientras que el Double objeto no.

// 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);
// The example displays the following output:
//    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
' Create a BigInteger from a large double value.
Dim doubleValue As Double = -6e20
Dim bigIntValue As 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 += 1
bigIntValue += BigInteger.One
Console.WriteLine("Incremented Double value: {0:N0}", doubleValue)
Console.WriteLine("Incremented BigInteger value: {0:N0}", bigIntValue)
' The example displays the following output:
'    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

Comentarios

Cualquier parte fraccionaria del value parámetro se trunca al crear una instancia de un BigInteger objeto.

Debido a la falta de precisión del Double tipo de datos, llamar a este constructor puede provocar la pérdida de datos.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor que resulta de asignar explícitamente un Double valor a .BigInteger

Se aplica a

BigInteger(Int32)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger usando un valor entero de 32 bits con signo.

public:
 BigInteger(int value);
public BigInteger (int value);
new System.Numerics.BigInteger : int -> System.Numerics.BigInteger
Public Sub New (value As Integer)

Parámetros

value
Int32

Entero de 32 bits con signo.

Ejemplos

En el ejemplo siguiente se llama al BigInteger(Int32) constructor para crear BigInteger instancias de valores de una matriz de enteros de 32 bits. También usa la conversión implícita para asignar cada valor entero de 32 bits a una BigInteger variable. A continuación, compara los dos valores para establecer que los valores resultantes BigInteger son los mismos.

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));
}
// The example displays the following output:
//       -2147483648 = -2147483648: True
//       -10534 = -10534: True
//       -189 = -189: True
//       0 = 0: True
//       17 = 17: True
//       113439 = 113439: True
//       2147483647 = 2147483647: True
Dim integers() As Integer = { Int32.MinValue, -10534, -189, 0, 17, 113439,
                              Int32.MaxValue }
Dim constructed, assigned As BigInteger

For Each number As Integer In integers
   constructed = New BigInteger(number)
   assigned = number
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)) 
Next
' The example displays the following output:
'       -2147483648 = -2147483648: True
'       -10534 = -10534: True
'       -189 = -189: True
'       0 = 0: True
'       17 = 17: True
'       113439 = 113439: True
'       2147483647 = 2147483647: True

Comentarios

No se pierde la precisión al crear una instancia de un BigInteger objeto mediante este constructor.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor resultante de asignar un Int32 valor a .BigInteger

La BigInteger estructura no incluye constructores con un parámetro de tipo Byte, Int16, SByteo UInt16. Sin embargo, el Int32 tipo admite la conversión implícita de enteros de 8 y 16 bits con signo y sin signo en enteros de 32 bits con signo. Como resultado, se llama a este constructor si value es cualquiera de estos cuatro tipos enteros.

Se aplica a

BigInteger(Int64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger usando un valor entero de 64 bits con signo.

public:
 BigInteger(long value);
public BigInteger (long value);
new System.Numerics.BigInteger : int64 -> System.Numerics.BigInteger
Public Sub New (value As Long)

Parámetros

value
Int64

Entero de 64 bits con signo.

Ejemplos

En el ejemplo siguiente se llama al BigInteger(Int64) constructor para crear BigInteger instancias de valores de una matriz de enteros de 64 bits. También usa la conversión implícita para asignar cada valor entero de 64 bits a una BigInteger variable. A continuación, compara los dos valores para establecer que los valores resultantes BigInteger son los mismos.

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));
}
// The example displays the following output:
//       -2147483648 = -2147483648: True
//       -10534 = -10534: True
//       -189 = -189: True
//       0 = 0: True
//       17 = 17: True
//       113439 = 113439: True
//       2147483647 = 2147483647: True
Dim longs() As Long = { Int64.MinValue, -10534, -189, 0, 17, 113439,
                              Int64.MaxValue }
Dim constructed, assigned As BigInteger

For Each number As Long In longs
   constructed = New BigInteger(number)
   assigned = number
   Console.WriteLine("{0} = {1}: {2}", constructed, assigned, 
                     constructed.Equals(assigned)) 
Next
' The example displays the following output:
'       -2147483648 = -2147483648: True
'       -10534 = -10534: True
'       -189 = -189: True
'       0 = 0: True
'       17 = 17: True
'       113439 = 113439: True
'       2147483647 = 2147483647: True

Comentarios

No se pierde la precisión al crear una instancia de un BigInteger objeto mediante este constructor.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor resultante de asignar un Int64 valor a .BigInteger

Se aplica a

BigInteger(Single)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor de punto flotante de precisión sencilla.

public:
 BigInteger(float value);
public BigInteger (float value);
new System.Numerics.BigInteger : single -> System.Numerics.BigInteger
Public Sub New (value As Single)

Parámetros

value
Single

Valor de punto flotante de precisión sencilla.

Excepciones

Ejemplos

En el ejemplo siguiente se muestra el uso del BigInteger(Single) constructor para crear una instancia de un BigInteger objeto . También muestra la pérdida de precisión que puede producirse al usar el Single tipo de datos. Single Se asigna un valor negativo grande, que luego se asigna a un BigInteger objeto . Como se muestra en la salida, esta asignación implica una pérdida de precisión. Ambos valores se incrementan en uno. La salida muestra que el BigInteger objeto refleja el valor cambiado, mientras que el Single objeto no lo hace.

// 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"));
// The example displays the following output:
//       -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
' Create a BigInteger from a large negative Single value
Dim negativeSingle As Single = Single.MinValue
Dim negativeNumber As New BigInteger(negativeSingle)

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

negativeSingle += 1
negativeNumber += 1
Console.WriteLine(negativeSingle.ToString("N0"))
Console.WriteLine(negativeNumber.ToString("N0"))
' The example displays the following output:
'       -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

Comentarios

Cualquier parte fraccionaria del value parámetro se trunca al crear una instancia de un BigInteger objeto.

Debido a la falta de precisión del Single tipo de datos, llamar a este constructor puede provocar la pérdida de datos.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor que resulta de asignar explícitamente un Single valor a .BigInteger

Se aplica a

BigInteger(UInt32)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Esta API no es conforme a CLS.

Alternativa conforme a CLS
System.Numerics.BigInteger.BigInteger(Int64)

Inicializa una nueva instancia de la estructura BigInteger utilizando un valor entero de 32 bits sin signo.

public:
 BigInteger(System::UInt32 value);
[System.CLSCompliant(false)]
public BigInteger (uint value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : uint32 -> System.Numerics.BigInteger
Public Sub New (value As UInteger)

Parámetros

value
UInt32

Valor entero de 32 bits sin signo.

Atributos

Ejemplos

En el ejemplo siguiente se usa el BigInteger(UInt32) constructor y una instrucción de asignación para inicializar BigInteger valores de una matriz de enteros de 32 bits sin signo. A continuación, compara los dos valores para demostrar que los dos métodos de inicialización de un BigInteger valor generan resultados idénticos.

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);
}
// The example displays the following output:
//    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.
Dim unsignedValues() As UInteger = { 0, 16704, 199365, UInt32.MaxValue }
For Each unsignedValue As UInteger In unsignedValues
   Dim constructedNumber As New BigInteger(unsignedValue)
   Dim assignedNumber As BigInteger = unsignedValue
   If constructedNumber.Equals(assignedNumber) Then
      Console.WriteLine("Both methods create a BigInteger whose value is {0:N0}.",
                        constructedNumber)
   Else
      Console.WriteLine("{0:N0} ≠ {1:N0}", constructedNumber, assignedNumber)
   End If                         
Next
' The example displays the following output:
'    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.

Comentarios

No se pierde la precisión al crear una instancia de mediante BigInteger este constructor.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor que resulta de asignar un UInt32 valor a .BigInteger

Se aplica a

BigInteger(UInt64)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Importante

Esta API no es conforme a CLS.

Alternativa conforme a CLS
System.Numerics.BigInteger.BigInteger(Double)

Inicializa una nueva instancia de la estructura BigInteger con un valor entero de 64 bits sin signo.

public:
 BigInteger(System::UInt64 value);
[System.CLSCompliant(false)]
public BigInteger (ulong value);
[<System.CLSCompliant(false)>]
new System.Numerics.BigInteger : uint64 -> System.Numerics.BigInteger
Public Sub New (value As ULong)

Parámetros

value
UInt64

Entero de 64 bits sin signo.

Atributos

Ejemplos

En el ejemplo siguiente se usa el BigInteger(UInt64) constructor para crear una instancia de un BigInteger objeto cuyo valor es igual a MaxValue.

ulong unsignedValue = UInt64.MaxValue;
BigInteger number = new BigInteger(unsignedValue);
Console.WriteLine(number.ToString("N0"));
// The example displays the following output:
//       18,446,744,073,709,551,615
Dim unsignedValue As ULong = UInt64.MaxValue
Dim number As New BigInteger(unsignedValue)
Console.WriteLine(number.ToString("N0"))       
' The example displays the following output:
'       18,446,744,073,709,551,615

Comentarios

No se pierde la precisión al crear una instancia de mediante BigInteger este constructor.

El BigInteger valor resultante de llamar a este constructor es idéntico al valor que resulta de asignar un UInt64 valor a .BigInteger

Se aplica a

BigInteger(ReadOnlySpan<Byte>, Boolean, Boolean)

Source:
BigInteger.cs
Source:
BigInteger.cs
Source:
BigInteger.cs

Inicializa una nueva instancia de la estructura BigInteger mediante los valores de un intervalo de solo lectura de bytes y, de forma opcional, indica la codificación de firma y el orden de bytes endianness.

public BigInteger (ReadOnlySpan<byte> value, bool isUnsigned = false, bool isBigEndian = false);
new System.Numerics.BigInteger : ReadOnlySpan<byte> * bool * bool -> System.Numerics.BigInteger
Public Sub New (value As ReadOnlySpan(Of Byte), Optional isUnsigned As Boolean = false, Optional isBigEndian As Boolean = false)

Parámetros

value
ReadOnlySpan<Byte>

Intervalo de solo lectura de bytes que representa el entero grande.

isUnsigned
Boolean

true para indicar que value usa codificación sin signo; de lo contrario, false (el valor predeterminado).

isBigEndian
Boolean

true es para indicar value que está en orden de bytes big-endian; en caso contrario, false (el valor predeterminado).

Se aplica a