當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET BigInteger結構體代碼示例

本文整理匯總了VB.NET中System.Numerics.BigInteger結構體的典型用法代碼示例。如果您正苦於以下問題:VB.NET BigInteger結構體的具體用法?VB.NET BigInteger怎麽用?VB.NET BigInteger使用的例子?那麽, 這裏精選的結構體代碼示例或許可以為您提供幫助。


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

示例1: BigInteger

Dim bigIntFromDouble As New BigInteger(179032.6541)
Console.WriteLine(bigIntFromDouble)
Dim bigIntFromInt64 As New BigInteger(934157136952)
Console.WriteLine(bigIntFromInt64)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:4,代碼來源:BigInteger

輸出:

179032
934157136952

示例2:

Dim longValue As Long = 6315489358112      
Dim assignedFromLong As BigInteger = longValue
Console.WriteLine(assignedFromLong)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:3,代碼來源:BigInteger

輸出:

6315489358112

示例3: CType

Dim assignedFromDouble As BigInteger = CType(179032.6541, BigInteger)
Console.WriteLine(assignedFromDouble)   
Dim assignedFromDecimal As BigInteger = CType(64312.65d, BigInteger)      
Console.WriteLine(assignedFromDecimal)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:4,代碼來源:BigInteger

輸出:

179032
64312

示例4: byteArray

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)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:3,代碼來源:BigInteger

輸出:

The value of newBigInt is 4759477275222530853130 (or 0x102030405060708090a).

示例5:

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
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:19,代碼來源:BigInteger

輸出:

9.1389681247993671255432112E+31
-9.0315837410896312071002088037E+34

示例6:

Dim number As BigInteger = BigInteger.Pow(UInt64.MaxValue, 3)
Console.WriteLine(number)
' The example displays the following output:
  ' 6277101735386680762814942322444851025767571854389858533375
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:4,代碼來源:BigInteger

示例7:

Dim number As BigInteger = BigInteger.Multiply(Int64.MaxValue, 3)
number += 1
Console.WriteLine(number)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:3,代碼來源:BigInteger

示例8: SomeOperationSucceeds

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
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:9,代碼來源:BigInteger

示例9: SomeOperationSucceeds

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
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:11,代碼來源:BigInteger

示例10: bytes

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)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:15,代碼來源:BigInteger

輸出:

8.5070591730234615847396907784E+37
0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x3F

8.5070591730234615847396907784E+37

示例11: bytes

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)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:15,代碼來源:BigInteger

輸出:

30000
0x30 0x75
30000

示例12: negativeBytes

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"))
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:12,代碼來源:BigInteger

輸出:

-1,000,000
4,293,967,296

示例13: bytes

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"))
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:22,代碼來源:BigInteger

輸出:

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

示例14:

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)
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:16,代碼來源:BigInteger

輸出:

Converted -1,000,000 to F0BDC0 back to -1,000,000.
Converted 15,777,216 to 0F0BDC0 back to 15,777,216.

示例15: Example

' 導入命名空間
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
開發者ID:VB.NET開發者,項目名稱:System.Numerics,代碼行數:38,代碼來源:BigInteger

輸出:

Converted 4039543321 to F0C68A19 and back to 4039543321.
Converted -255423975 to f0c68a19 and back to -255423975.


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