本文整理汇总了C#中System.Collections.BitArray.Not方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Not方法的具体用法?C# BitArray.Not怎么用?C# BitArray.Not使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.BitArray
的用法示例。
在下文中一共展示了BitArray.Not方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections;
public class SamplesBitArray {
public static void Main() {
// Creates and initializes two BitArrays of the same size.
BitArray myBA1 = new BitArray( 4 );
BitArray myBA2 = new BitArray( 4 );
myBA1[0] = myBA1[1] = false;
myBA1[2] = myBA1[3] = true;
myBA2[0] = myBA2[2] = false;
myBA2[1] = myBA2[3] = true;
// Performs a bitwise NOT operation between BitArray instances of the same size.
Console.WriteLine( "Initial values" );
Console.Write( "myBA1:" );
PrintValues( myBA1, 8 );
Console.Write( "myBA2:" );
PrintValues( myBA2, 8 );
Console.WriteLine();
myBA1.Not();
myBA2.Not();
Console.WriteLine( "After NOT" );
Console.Write( "myBA1:" );
PrintValues( myBA1, 8 );
Console.Write( "myBA2:" );
PrintValues( myBA2, 8 );
Console.WriteLine();
}
public static void PrintValues( IEnumerable myList, int myWidth ) {
int i = myWidth;
foreach ( Object obj in myList ) {
if ( i <= 0 ) {
i = myWidth;
Console.WriteLine();
}
i--;
Console.Write( "{0,8}", obj );
}
Console.WriteLine();
}
}
输出:
Initial values myBA1: False False True True myBA2: False True False True After NOT myBA1: True True False False myBA2: True False True False
示例2: BitArray.Not()
//引入命名空间
using System;
using System.Collections;
public class BADemo {
public static void showbits(string rem,
BitArray bits) {
Console.WriteLine(rem);
for(int i=0; i < bits.Count; i++)
Console.Write("{0, -6} ", bits[i]);
Console.WriteLine("\n");
}
public static void Main() {
BitArray ba = new BitArray(8);
byte[] b = { 67 };
BitArray ba2 = new BitArray(b);
showbits("Original contents of ba:", ba);
ba = ba.Not();
showbits("Contents of ba after Not:", ba);
showbits("Contents of ba2:", ba2);
BitArray ba3 = ba.Xor(ba2);
showbits("Result of ba XOR ba2:", ba3);
}
}