BigInteger.OnesComplement(BigInteger) 연산자

정의

BigInteger 값에 대한 비트 1의 보수를 반환합니다.

public:
 static System::Numerics::BigInteger operator ~(System::Numerics::BigInteger value);
public:
 static System::Numerics::BigInteger operator ~(System::Numerics::BigInteger value) = System::Numerics::IBitwiseOperators<System::Numerics::BigInteger, System::Numerics::BigInteger, System::Numerics::BigInteger>::op_OnesComplement;
public static System.Numerics.BigInteger operator ~ (System.Numerics.BigInteger value);
static member op_OnesComplement : System.Numerics.BigInteger -> System.Numerics.BigInteger
Public Shared Operator Not (value As BigInteger) As BigInteger

매개 변수

value
BigInteger

정수 값입니다.

반환

BigInteger

value에 대한 비트 1의 보수입니다.

구현

설명

이 메서드는 OnesComplement 값에 대한 비트 원의 보수 연산자 연산을 BigInteger 정의합니다. 비트 1의 보수 연산자는 각 비트를 숫자 값으로 되돌려 줍니다. 즉, 0인 비트는 결과에서 value 1로 설정되고 1인 비트는 결과에서 0으로 설정됩니다. 이 메서드는 OnesComplement 다음과 같은 코드를 사용하도록 설정합니다.

using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      BigInteger value, complement;

      value = BigInteger.Multiply(BigInteger.One, 9);
      complement = ~value;

      Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value));
      Console.WriteLine("{0,5} -- {1,-32}\n", complement, DisplayInBinary(complement));

      value = BigInteger.MinusOne * SByte.MaxValue;
      complement = ~value;

      Console.WriteLine("{0,5} -- {1,-32}", value, DisplayInBinary(value));
      Console.WriteLine("{0,5} -- {1,-32}\n", complement, DisplayInBinary(complement));
   }

   private static string DisplayInBinary(BigInteger number)
   {
      byte[] bytes = number.ToByteArray();
      string binaryString = string.Empty;
      foreach (byte byteValue in bytes)
      {
         string byteString = Convert.ToString(byteValue, 2).Trim();
         binaryString += byteString.Insert(0, new string('0', 8 - byteString.Length));
      }
      return binaryString;
   }
}
// The example displays the following output:
//           9 -- 00001001
//         -10 -- 11110110
//
//        -127 -- 10000001
//         126 -- 01111110
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
' The example displays the following output:
'           9 -- 00001001
'         -10 -- 11110110
'       
'        -127 -- 10000001
'         126 -- 01111110

사용자 지정 연산자를 지원하지 않는 언어는 메서드를 직접 호출 OnesComplement 하여 비트 단위의 보수 작업을 수행할 수 있습니다. 예를 들면 다음과 같습니다.

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

적용 대상