本文整理汇总了VB.NET中System.Numerics.BigInteger.OnesComplement操作符的典型用法代码示例。如果您正苦于以下问题:VB.NET BigInteger.OnesComplement操作符的具体用法?VB.NET BigInteger.OnesComplement怎么用?VB.NET BigInteger.OnesComplement使用的例子?那么, 这里精选的操作符代码示例或许可以为您提供帮助。您也可以进一步了解该操作符所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.OnesComplement操作符的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Numerics
Module Example
Public Sub Main()
Dim value, complement As bigInteger
value = BigInteger.Multiply(BigInteger.One, 9)
complement = Not value
Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value))
Console.WriteLine("{0,5} -- {1,-32}", complement, DisplayInBinary(complement))
Console.WriteLine()
value = BigInteger.MinusOne * SByte.MaxValue
complement = BigInteger.op_OnesComplement(value)
Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value))
Console.WriteLine("{0,5} -- {1,-32}", complement, DisplayInBinary(complement))
Console.WriteLine()
End Sub
Private Function DisplayInBinary(number As BigInteger) As String
Dim bytes() As Byte = number.ToByteArray()
Dim binaryString As String = String.Empty
For Each byteValue As Byte In bytes
Dim byteString As String = Convert.ToString(byteValue, 2).Trim()
binaryString += byteString.Insert(0, New String("0"c, 8 - byteString.Length))
Next
Return binaryString
End Function
End Module
输出:
9 -- 00001001 -10 -- 11110110 -127 -- 10000001 126 -- 01111110
示例2: Example
' 导入命名空间
Imports System.Numerics
Module Example
Public Sub Main()
Dim value, complement As bigInteger
value = BigInteger.Multiply(BigInteger.One, 9)
complement = BigInteger.op_OnesComplement(value)
Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value))
Console.WriteLine("{0,5} -- {1,-32}", complement, DisplayInBinary(complement))
Console.WriteLine()
value = BigInteger.MinusOne * SByte.MaxValue
complement = BigInteger.op_OnesComplement(value)
Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value))
Console.WriteLine("{0,5} -- {1,-32}", complement, DisplayInBinary(complement))
Console.WriteLine()
End Sub
Private Function DisplayInBinary(number As BigInteger) As String
Dim bytes() As Byte = number.ToByteArray()
Dim binaryString As String = String.Empty
For Each byteValue As Byte In bytes
Dim byteString As String = Convert.ToString(byteValue, 2).Trim()
binaryString += byteString.Insert(0, New String("0"c, 8 - byteString.Length))
Next
Return binaryString
End Function
End Module
输出:
9 -- 00001001 -10 -- 11110110 -127 -- 10000001 126 -- 01111110