vb System.Numerics.BigInteger类(方法)实例源码

下面列出了vb System.Numerics.BigInteger 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:System.Numeric   
Dim bigIntFromDouble As New BigInteger(179032.6541)
Console.WriteLine(bigIntFromDouble)
Dim bigIntFromInt64 As New BigInteger(934157136952)
Console.WriteLine(bigIntFromInt64)

作者:VB.NET开发    项目:System.Numeric   
Dim longValue As Long = 6315489358112      
Dim assignedFromLong As BigInteger = longValue
Console.WriteLine(assignedFromLong)

作者:VB.NET开发    项目:System.Numeric   
Dim assignedFromDouble As BigInteger = CType(179032.6541, BigInteger)
Console.WriteLine(assignedFromDouble)   
Dim assignedFromDecimal As BigInteger = CType(64312.65d, BigInteger)      
Console.WriteLine(assignedFromDecimal)

作者:VB.NET开发    项目:System.Numeric   
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)

作者:VB.NET开发    项目:System.Numeric   
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

作者:VB.NET开发    项目:System.Numeric   
Dim number As BigInteger = BigInteger.Pow(UInt64.MaxValue, 3)
Console.WriteLine(number)
' The example displays the following output:
  ' 6277101735386680762814942322444851025767571854389858533375

作者:VB.NET开发    项目:System.Numeric   
Dim number As BigInteger = BigInteger.Multiply(Int64.MaxValue, 3)
number += 1
Console.WriteLine(number)

作者:VB.NET开发    项目:System.Numeric   
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

作者:VB.NET开发    项目:System.Numeric   
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

作者:VB.NET开发    项目:System.Numeric   
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)

作者:VB.NET开发    项目:System.Numeric   
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)

作者:VB.NET开发    项目:System.Numeric   
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"))

作者:VB.NET开发    项目:System.Numeric   
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"))

作者:VB.NET开发    项目:System.Numeric   
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)

作者:VB.NET开发    项目:System.Numeric   
' 导入命名空间
Imports System.Globalization
Imports System.Numerics

Public Structure HexValue
   Public Sign As Integer
   Public Value As String
End Structure
   
Module Example
   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


问题


面经


文章

微信
公众号

扫码关注公众号