OnesComplement Operator

BigInteger.OnesComplement Operator (BigInteger)

 

Returns the bitwise one's complement of a BigInteger value.

Namespace:   System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

static let inline (null)
        value:BigInteger : BigInteger

Parameters

value
Type: System.Numerics.BigInteger

An integer value.

Return Value

Type: System.Numerics.BigInteger

The bitwise one's complement of value.

The OnesComplement method defines the operation of the bitwise one's complement operator for BigInteger values. The bitwise one's complement operator reverses each bit in a numeric value. That is, bits in value that are 0 are set to 1 in the result, and bits that are 1 are set to 0 in the result. The OnesComplement method enables code such as the following:

No code example is currently available or this language may not be supported.

Languages that do not support custom operators may be able to call the OnesComplement method directly to perform a bitwise one's complement operation. For 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
' The example displays the following output:
'           9 -- 00001001
'         -10 -- 11110110
'       
'        -127 -- 10000001
'         126 -- 01111110

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 4.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft