BigInteger.OnesComplement(BigInteger) 演算子
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
整数値。
戻り値
value
のビットごとの 1 の補数。
実装
注釈
メソッドは OnesComplement 、値に対するビットごとの 1 の補数演算子の演算を 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
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示