当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.Not方法代码示例

本文整理汇总了C#中System.Collections.BitArray.Not方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Not方法的具体用法?C# BitArray.Not怎么用?C# BitArray.Not使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.Not方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: feistelFunction

 private BitArray feistelFunction(BitArray keyBits, BitArray Bittext_16)
 {
     BitArray afterParity = Bittext_16;
     if (checkParity(keyBits)) //true if parity is even
     {
         afterParity = Bittext_16.Not();
         //Console.WriteLine("Right after negating : " + BitOperations.getBinaryString(afterParity));
     }
     //Console.WriteLine("Keybits for xoring : " + BitOperations.getBinaryString(keyBits));
     var feistelOutput = keyBits.Xor(new BitArray(afterParity));
     //Console.WriteLine("right 16 bits after fiestal function : " + BitOperations.getBinaryString(a));
     return feistelOutput;
 }
开发者ID:AravindSreenivasa,项目名称:AppliedCryptography,代码行数:13,代码来源:decryption.cs

示例2: BitArrayToText

        public void BitArrayToText() {
            var bitArray = new BitArray(32);

            var bitString = bitArray.ToText();
            Assert.AreEqual(32, bitString.Length);
            Assert.IsFalse(bitString.Contains("1"));
            Assert.IsTrue(bitString.All(c => c == '0'));

            bitString = bitArray.Not().ToText();
            Assert.AreEqual(32, bitString.Length);
            Assert.IsFalse(bitString.Contains("0"));
            Assert.IsTrue(bitString.All(c => c == '1'));
        }
开发者ID:debop,项目名称:NFramework,代码行数:13,代码来源:BitToolFixture.cs

示例3: BitArrayToBytes

        public void BitArrayToBytes() {
            var bitArray = new BitArray(32);

            var bytes = bitArray.ToBytes();
            Assert.AreEqual(32 / BitTool.ByteLength, bytes.Length);

            Assert.IsTrue(bytes.All(b => b == 0x00));

            Assert.IsTrue(bytes.GetHexStringFromBytes().All(c => c == '0'));

            bytes = bitArray.Not().ToBytes();
            Assert.IsTrue(bytes.GetHexStringFromBytes().All(c => c == 'F'));

            // Console.WriteLine(bytes.GetHexStringFromBytes());
        }
开发者ID:debop,项目名称:NFramework,代码行数:15,代码来源:BitToolFixture.cs

示例4: BitArray_NotTest

            public static void BitArray_NotTest()
            {
                // []  Standard cases 

                BitArray ba2 = null;
                BitArray ba4 = null;

                ba2 = new BitArray(6, false);

                ba2.Set(0, true);
                ba2.Set(1, true);

                ba4 = ba2.Not();

                for (int i = 0; i < ba4.Length; i++)
                {
                    if (i <= 1)
                        Assert.False(ba4.Get(i)); //"Err_2! ba4.Get(" + i + ") should be false"
                    else
                        Assert.True(ba4.Get(i)); //"Err_3! ba4.Get(" + i + ") should be true"
                }



                // []  Size stress cases.
                ba2 = new BitArray(0x1000F, false);

                ba2.Set(0, true);
                ba2.Set(1, true);

                ba2.Set(0x10000, true);
                ba2.Set(0x10001, true);

                ba4 = ba2.Not();

                Assert.False(ba4.Get(1)); //"Err_4! ba4.Get(1) should be false"
                Assert.True(ba4.Get(2)); //"Err_5! ba4.Get(2) should be true"

                for (int i = 0x10000; i < ba2.Length; i++)
                {
                    if (i <= 0x10001)
                        Assert.False(ba4.Get(i)); //"Err_6! ba4.Get(" + i + ") should be false"
                    else
                        Assert.True(ba4.Get(i)); //"Err_7! ba4.Get(" + i + ") should be true"
                }
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:46,代码来源:BitArray_OperatorsTests.cs

示例5: BitArrayDemo

        static void BitArrayDemo()
        {
            var bits1 = new BitArray(8);
            bits1.SetAll(true);
            bits1.Set(1, false);
            bits1[5] = false;
            bits1[7] = false;
            Console.Write("initialized: ");
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits1);
            bits1.Not();
            Console.Write(" not ");
            DisplayBits(bits1);
            Console.WriteLine();

            var bits2 = new BitArray(bits1);
            bits2[0] = true;
            bits2[1] = false;
            bits2[4] = true;
            DisplayBits(bits1);
            Console.Write(" or ");
            DisplayBits(bits2);
            Console.Write(" : ");
            bits1.Or(bits2);
            DisplayBits(bits1);
            Console.WriteLine();

            DisplayBits(bits2);
            Console.Write(" and ");
            DisplayBits(bits1);
            Console.Write(" : ");
            bits2.And(bits1);
            DisplayBits(bits2);
            Console.WriteLine();

            DisplayBits(bits1);
            Console.Write(" xor ");
            DisplayBits(bits2);
            bits1.Xor(bits2);
            Console.Write(" : ");
            DisplayBits(bits1);
            Console.WriteLine();
        }
开发者ID:CSharpDev,项目名称:Csharp,代码行数:45,代码来源:Program.cs

示例6: Negative

 /// <summary>
 /// Takes bits array of positive number and make this number negative.
 /// First invert input bit array, then adds 1. That makes positive number negative.
 /// </summary>
 /// <param name="arr">Bit array of positive number</param>
 private void Negative(BitArray arr)
 {
     arr.Not();
     bool overflow = false;
     for (int i = 0; i < arr.Length; i++)
         if (i == 0)
         {
             if (arr[0] & true) overflow = true;
             arr[0] ^= true;
         }
         else if (overflow)
         {
             if (!(arr[i] & true))
                 overflow = false;
             arr[i] ^= true;
         }
         else break;
 }
开发者ID:AlexNav73,项目名称:EPAM_ASP.NET,代码行数:23,代码来源:Converter.cs

示例7: Parse

            public BitArray/*!*/ Parse() {
                _pos = 0;

                BitArray result = new BitArray(256);
                if (_range.Length == 0) {
                    return result;
                }

                bool negate = false;
                if (_range.GetChar(0) == '^') {
                    // Special case of ^
                    if (_range.Length == 1) {
                        result.Set('^', true);
                        return result;
                    }

                    negate = true;
                    _pos = 1;
                    result.Not();
                }

                int c;
                while ((c = NextToken()) != -1) {
                    if (_rangeStarted) {
                        // _startRange - c. ignore ranges which are the reverse sequence
                        if (_startRange <= c) {
                            for (int i = _startRange; i <= c; ++i)
                                result.Set(i, !negate);
                        }
                        _rangeStarted = false;
                    } else {
                        int p = PeekChar();
                        if (p == '-') {
                            // z- is treated as a literal 'z', '-'
                            if (_pos == _range.Length - 1) {
                                result.Set(c, !negate);
                                result.Set('-', !negate);
                                break;
                            }

                            _startRange = c;
                            if (_rangeStarted) {
                                result.Set('-', !negate);
                                _rangeStarted = false;
                            } else {
                                _rangeStarted = true;
                            }
                            _pos++; // consume -
                        } else {
                            result.Set(c, !negate);
                        }
                    }
                }

                return result;
            }
开发者ID:mscottford,项目名称:ironruby,代码行数:56,代码来源:MutableStringOps.cs

示例8: ParseSequence

            // TODO: refactor this and Parse()
            public MutableString/*!*/ ParseSequence() {
                _pos = 0;

                MutableString result = MutableString.CreateBinary();
                if (_range.Length == 0) {
                    return result;
                }

                bool negate = false;
                if (_range.GetChar(0) == '^') {
                    // Special case of ^
                    if (_range.Length == 1) {
                        result.Append('^');
                        return result;
                    }

                    negate = true;
                    _pos = 1;
                }

                BitArray array = new BitArray(256);
                array.Not();

                int c;
                while ((c = NextToken()) != -1) {
                    if (_rangeStarted) {
                        // _startRange - c. ignore ranges which are the reverse sequence
                        if (_startRange <= c) {
                            for (int i = _startRange; i <= c; ++i) {
                                if (negate) {
                                    array.Set(i, false);
                                } else {
                                    result.Append((byte)i);
                                }
                            }
                        }
                        _rangeStarted = false;
                    } else {
                        int p = PeekChar();
                        if (p == '-') {
                            // z- is treated as a literal 'z', '-'
                            if (_pos == _range.Length - 1) {
                                if (negate) {
                                    array.Set(c, false);
                                    array.Set('-', false);
                                } else {
                                    result.Append((byte)c);
                                    result.Append('-');
                                }
                                break;
                            }

                            _startRange = c;
                            if (_rangeStarted) {
                                if (negate) {
                                    array.Set('-', false);
                                } else {
                                    result.Append('-');
                                }
                                _rangeStarted = false;
                            } else {
                                _rangeStarted = true;
                            }
                            _pos++; // consume -
                        } else {
                            if (negate) {
                                array.Set(c, false);
                            } else {
                                result.Append((byte)c);
                            }
                        }
                    }
                }

                if (negate) {
                    for (int i = 0; i < 256; i++) {
                        if (array.Get(i)) {
                            result.Append((byte)i);
                        }
                    }
                }
                return result;
            }
开发者ID:mscottford,项目名称:ironruby,代码行数:84,代码来源:MutableStringOps.cs

示例9: Minus

 public void Minus(HasseFingerprint FP)
 {
     // do this AND (NOT that)
     BitArray fpx= new BitArray (FP.fp);
     fpx.Not ();
     fp.And(fpx);
     this.bitCount = this.CountBits();
 }
开发者ID:peter-lind,项目名称:hasse-manager,代码行数:8,代码来源:HasseFingerprints.cs

示例10: AddClsTrans

 /// <summary>
 /// Add a transition from NState "this"
 /// to NState "nxt", for each character
 /// value in the leaf range list.
 /// If the characters are packed, transform 
 /// from character ordinal to equivalence class 
 /// ordinal.
 /// </summary>
 /// <param name="leaf">The regex leaf node</param>
 /// <param name="nxt">The destination state</param>
 public void AddClsTrans(Leaf leaf, NState nxt)
 {
     BitArray cls = new BitArray(myNfaInst.MaxSym);
     if (myNfaInst.Pack)
     {
         foreach (int ord in leaf.rangeLit.equivClasses)
             cls[ord] = true;
     }
     else
     {
         foreach (CharRange rng in leaf.rangeLit.list.Ranges)
             for (int i = rng.minChr; i <= rng.maxChr; i++)
                 cls[i] = true;
         if (leaf.rangeLit.list.IsInverted)
             cls = cls.Not();
     }
     AddClsTrans(cls, nxt);
 }
开发者ID:spark-shading-language,项目名称:spark,代码行数:28,代码来源:NFSA.cs

示例11: AddClsTrans

            /// <summary>
            /// Add a transition from NState "this"
            /// to NState "nxt", for each character
            /// value in the leaf range list.
            /// If the characters are packed, transform 
            /// from character ordinal to equivalence class 
            /// ordinal.
            /// </summary>
            /// <param name="leaf">The regex leaf node</param>
            /// <param name="nxt">The destination state</param>
            public void AddClsTrans(Leaf leaf, NState nxt)
            {
                if (myNfaInst.parent.task.CaseAgnostic) {
                    leaf.rangeLit.list = leaf.rangeLit.list.MakeCaseAgnosticList();
                    leaf.rangeLit.list.Canonicalize();
                }

                BitArray cls = new BitArray(myNfaInst.MaxSym);
                if (myNfaInst.Pack)
                {
                    foreach (int ord in leaf.rangeLit.equivClasses)
                        cls[ord] = true;
                }
                else
                {
                    foreach (CharRange rng in leaf.rangeLit.list.Ranges)
                        for (int i = rng.minChr; i <= rng.maxChr; i++)
                            cls[i] = true;
                    if (leaf.rangeLit.list.IsInverted)
                        cls = cls.Not();
                }
                AddClsTrans(cls, nxt);
            }
开发者ID:dbremner,项目名称:gplex,代码行数:33,代码来源:NFSA.cs

示例12: AndNot

 public static BitArray AndNot(BitArray b1, BitArray b2)
 {
     if (b1.Length > b2.Length)
     {
         b2.Length = b1.Length;
     }
     else if (b2.Length > b1.Length)
     {
         b1.Length = b2.Length;
     }
     b1.And(b2.Not());
     return b1;
 }
开发者ID:DONGChuan,项目名称:LGame,代码行数:13,代码来源:CollectionUtils.cs

示例13: OnesComplement

        /// <summary>
        /// Gets one's complement of a signed integer
        /// </summary>
        /// <param name="number">signed integer (value) </param>
        /// <param name="index">number of bits in the signed int</param>
        /// <returns>one's complement of a signed int</returns>
        internal static int OnesComplement(int number, int bits)
        {
            // zero count offset
            bits--;

            // convert to bit array.
            BitArray compArray = new BitArray(BitConverter.GetBytes(number));

            // a true most significant bit (MSB) indicates a negative 
            // nubmer and all bits must be flipped (~).
            if (compArray.Get(bits))
            {
                // invert all bits (complement)
                compArray.Not();

                // set all unused bits to false.
                for (int i = bits; i < compArray.Length; i++)
                {
                    compArray[i] = false;
                }

                // convert bitarray to integer, using copyto.
                int[] retunArray = new int[1];
                compArray.CopyTo(retunArray, 0);

                // return negative complement
                return -(retunArray[0]);
            }

            // positive complement = binary representation
            return number;
        }
开发者ID:kewencai,项目名称:ChassisManager,代码行数:38,代码来源:SdrConversionFactors.cs

示例14: MakeChild

        public Genome MakeChild(Genome other, BitArray mask)
        {
            BitArray leftCopy = new BitArray(this.genome);
            BitArray rightCopy = new BitArray(other.genome);
            BitArray maskCopy = new BitArray(mask);

            leftCopy.And(maskCopy);
            rightCopy.And(maskCopy.Not());

            //BitArray temp2 = new BitArray(right.And(mask.Not()));
            return new Genome(leftCopy.Or(rightCopy));
        }
开发者ID:KalerPorter,项目名称:genetic,代码行数:12,代码来源:Genetic.cs

示例15: Main

        static void Main(string[] args)
        {
            // Creates an initializes several BitArrays.
            BitArray myBA1 = new BitArray(5);

            BitArray myBA2 = new BitArray(5, false);

            byte[] myBytes = new byte[5] { 1, 2, 3, 4, 5 };
            BitArray myBA3 = new BitArray(myBytes);

            bool[] myBools = new bool[5] { true, false, true, true, false };
            BitArray myBA4 = new BitArray(myBools);

            int[] myInts = new int[5] { 6, 7, 8, 9, 10 };
            BitArray myBA5 = new BitArray(myInts);

            // Displays the properties and values of the BitArrays.
            Console.WriteLine("myBA1");
            Console.WriteLine("   Count:    {0}", myBA1.Count);
            Console.WriteLine("   Length:   {0}", myBA1.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA1, 8);

            Console.WriteLine("myBA2");
            Console.WriteLine("   Count:    {0}", myBA2.Count);
            Console.WriteLine("   Length:   {0}", myBA2.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA2, 8);

            Console.WriteLine("myBA3");
            Console.WriteLine("   Count:    {0}", myBA3.Count);
            Console.WriteLine("   Length:   {0}", myBA3.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA3, 8);

            Console.WriteLine("myBA4");
            Console.WriteLine("   Count:    {0}", myBA4.Count);
            Console.WriteLine("   Length:   {0}", myBA4.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA4, 8);

            Console.WriteLine("myBA5");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA5, 8);

            int[] myAntiInts = new int[5] { -1, -1, -1, -1, -1 };
            BitArray myBA6 = new BitArray(myAntiInts);
            Console.WriteLine("myBA6");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA6, 8);

            Console.WriteLine("\nXORing BA5 with BA6...\n");
            BitArray myBA7 = myBA5.Xor(myBA6);
            Console.WriteLine("myBA7");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA7, 8);

            Console.WriteLine("myBA5");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA5, 8);

            Console.WriteLine("myBA6");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA6, 8);

            Console.WriteLine("\nNot on myBA5:\n");
            myBA5.Not();
            Console.WriteLine("myBA5");
            Console.WriteLine("   Count:    {0}", myBA5.Count);
            Console.WriteLine("   Length:   {0}", myBA5.Length);
            Console.WriteLine("   Values:");
            PrintValues(myBA5, 8);
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:83,代码来源:Program.cs


注:本文中的System.Collections.BitArray.Not方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。