本文整理匯總了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