当前位置: 首页>>代码示例>>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;未经允许,请勿转载。