BigInteger.OnesComplement(BigInteger) Operatore
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce il complemento a uno bit per bit di un valore BigInteger.
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
Valore intero.
Complemento a uno bit per bit dell'oggetto value
.
Il OnesComplement metodo definisce l'operazione dell'operatore di complemento bit per bit per BigInteger i valori. L'operatore di complemento bit per bit inverte ogni bit in un valore numerico. Ovvero, i bit in value
che sono 0 sono impostati su 1 nel risultato e i bit che sono 1 sono impostati su 0 nel risultato. Il OnesComplement metodo abilita il codice, ad esempio quanto segue:
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
open System
open System.Numerics
let displayInBinary (number: bigint) =
let bytes = number.ToByteArray()
let mutable binaryString = ""
for byteValue in bytes do
let byteString = Convert.ToString(byteValue, 2).Trim()
binaryString <- binaryString + byteString.PadLeft(8, '0')
binaryString
let value = BigInteger.Multiply(BigInteger.One, 9)
let complement = ~~~(int64 value) |> bigint
printfn "%5O -- %s" value (displayInBinary value)
printfn "%5O -- %s\n" complement (displayInBinary complement)
let value2 = BigInteger.MinusOne * (bigint SByte.MaxValue)
let complement2 = ~~~(int64 value) |> bigint
printfn "%5O -- %s" value2 (displayInBinary value2)
printfn "%5O -- %s" complement2 (displayInBinary complement2)
// 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
I linguaggi che non supportano operatori personalizzati possono chiamare il OnesComplement metodo direttamente per eseguire un'operazione di complemento bit per bit. Ad esempio:
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
Prodotto | Versioni |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Feedback su .NET
.NET è un progetto di open source. Selezionare un collegamento per fornire feedback: