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


C# BitArray.Xor方法代码示例

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


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

示例1: calcXor

    //for comparing two phash values
    public int calcXor(string str1,string str2)
    {
        //for the bitcount of no:of 1's
        int count = 0;

            //converting str1 to byte array
            byte[] byt_string1 = System.Text.Encoding.UTF8.GetBytes(str1);

            //converting byte array to bits
            BitArray bit_string1 = new BitArray(byt_string1);

            //converting str2 to byte array
            byte[] byt_string2 = System.Text.Encoding.UTF8.GetBytes(str2);

            //converting byte array to bits
            BitArray bit_string2 = new BitArray(byt_string2);

            //checking for equal size of bit array
            if (bit_string1.Length == bit_string2.Length)
            {
                bit_string1.Xor(bit_string2);
            }

            else
            {
                bit_string2.Length = bit_string1.Length;
                bit_string1.Xor(bit_string2);
            }

        for (int i = 0; i < bit_string1.Length; i++)
        {

         //   counting number of 1's in bit_string1[]
            if (bit_string1[i].Equals(true))
            {
                ++count;
            }
        }

        return count;
    }
开发者ID:danny4ever12,项目名称:Image_comparison,代码行数:42,代码来源:Default.aspx.cs

示例2: Xor_Invalid

        public static void Xor_Invalid()
        {
            BitArray bitArray1 = new BitArray(11, false);
            BitArray bitArray2 = new BitArray(6, false);

            // Different lengths
            Assert.Throws<ArgumentException>(null, () => bitArray1.Xor(bitArray2));
            Assert.Throws<ArgumentException>(null, () => bitArray2.Xor(bitArray1));

            Assert.Throws<ArgumentNullException>("value", () => bitArray1.Xor(null));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:11,代码来源:BitArray_OperatorsTests.cs

示例3: Xor_Operator

        public static void Xor_Operator(bool[] l, bool[] r, bool[] expected)
        {
            BitArray left = new BitArray(l);
            BitArray right = new BitArray(r);

            BitArray actual = left.Xor(right);
            Assert.Same(left, actual);
            Assert.Equal(actual.Length, expected.Length);

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i]);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:14,代码来源:BitArray_OperatorsTests.cs

示例4: OperatorTest

        public static void OperatorTest(Operator op)
        {
            BitArray bitArray1 = new BitArray(6, false);
            BitArray bitArray2 = new BitArray(6, false);
            BitArray result;

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

            bitArray2.Set(1, true);
            bitArray2.Set(2, true);

            switch (op)
            {
                case Operator.Xor:
                    result = bitArray1.Xor(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.True(result.Get(0));
                    Assert.False(result.Get(1));
                    Assert.True(result.Get(2));
                    Assert.False(result.Get(4));
                    break;

                case Operator.And:
                    result = bitArray1.And(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.False(result.Get(0));
                    Assert.True(result.Get(1));
                    Assert.False(result.Get(2));
                    Assert.False(result.Get(4));
                    break;

                case Operator.Or:
                    result = bitArray1.Or(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.True(result.Get(0));
                    Assert.True(result.Get(1));
                    Assert.True(result.Get(2));
                    Assert.False(result.Get(4));
                    break;
            }
            
            // Size stress cases.
            bitArray1 = new BitArray(0x1000F, false);
            bitArray2 = new BitArray(0x1000F, false);

            bitArray1.Set(0x10000, true); // The bit for 1 (2^0).
            bitArray1.Set(0x10001, true); // The bit for 2 (2^1).

            bitArray2.Set(0x10001, true); // The bit for 2 (2^1).

            switch (op)
            {
                case Operator.Xor:
                    result = bitArray1.Xor(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.True(result.Get(0x10000));
                    Assert.False(result.Get(0x10001));
                    Assert.False(result.Get(0x10002));
                    Assert.False(result.Get(0x10004));
                    break;

                case Operator.And:
                    result = bitArray1.And(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.False(result.Get(0x10000));
                    Assert.True(result.Get(0x10001));
                    Assert.False(result.Get(0x10002));
                    Assert.False(result.Get(0x10004));
                    break;

                case Operator.Or:
                    result = bitArray1.Or(bitArray2);
                    Assert.Same(bitArray1, result);
                    Assert.True(result.Get(0x10000));
                    Assert.True(result.Get(0x10001));
                    Assert.False(result.Get(0x10002));
                    Assert.False(result.Get(0x10004));
                    break;
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:81,代码来源:BitArray_OperatorsTests.cs

示例5: runTest

 public virtual bool runTest()
 {
     System.Console.Error.WriteLine( "BitArray- Co1552Xor runTest started." );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     BitArray ba2 = null;
     BitArray ba3 = null;
     BitArray ba4 = null;
     ba2 = new BitArray( 6 ,false );
     ba3 = new BitArray( 6 ,false );
     ba2.Set( 0 ,true );
     ba2.Set( 1 ,true );
     ba3.Set( 1 ,true );
     ba3.Set( 2 ,true );
     ba4 = ba2.Xor( ba3 );
     ++iCountTestcases;
     if ( ! ba4.Get( 0 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_572wb!" );
     }
     ++iCountTestcases;
     if ( ba4.Get( 1 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_733dl!" );
     }
     ++iCountTestcases;
     if ( ! ba4.Get( 2 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_678uf!" );
     }
     ++iCountTestcases;
     if ( ba4.Get( 4 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_628us!" );
     }
     ba2 = new BitArray( 0x1000F ,false );
     ba3 = new BitArray( 0x1000F ,false );
     ba2.Set( 0x10000 ,true ); 
     ba2.Set( 0x10001 ,true ); 
     ba3.Set( 0x10001 ,true ); 
     ba4 = ba2.Xor( ba3 );
     ++iCountTestcases;
     if ( ! ba4.Get( 0x10000 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_834at!" );
     }
     ++iCountTestcases;
     if ( ba4.Get( 0x10001 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_487ks!" );
     }
     ++iCountTestcases;
     if ( ba4.Get( 0x10002 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_312hr!" );
     }
     ++iCountTestcases;
     if ( ba4.Get( 0x10004 ) )
     {
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_805mx!" );
     }
     ba2 = new BitArray( 11 ,false );
     ba3 = new BitArray( 6 ,false );
     try
     {
         ++iCountTestcases;
         ba4 = ba2.Xor( ba3 );
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_909sq!" );
     }
     catch ( System.ArgumentException exc ) {}
     ba2 = new BitArray( 6 ,false );
     ba3 = null;
     try
     {
         ++iCountTestcases;
         ba4 = ba2.Xor( ba3 );
         ++iCountErrors;
         System.Console.Error.WriteLine( "Co1552Xor Error E_151zb!" );
     }
     catch ( System.ArgumentException exc ) {}
     if ( iCountErrors == 0 )
     {
         System.Console.Error.Write( "BitArray- Co1552Xor: paSs.  iCountTestcases==" );
         System.Console.Error.WriteLine( iCountTestcases );
         return true;
     }
     else
     {
         System.Console.Error.Write( "Co1552Xor iCountErrors==" );
         System.Console.Error.WriteLine( iCountErrors );
         System.Console.Error.WriteLine( "BitArray- Co1552Xor: FAiL!" );
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co1552xor.cs

示例6: GetConnectedPumpStations

    // returns a bitboard of all connected pump stations for the specified player
    public static BitArray GetConnectedPumpStations(int player)
    {
        // get bitboard of all pump stations for specified player
        BitArray pumpStations = new BitArray(length, false);
        if (player == myID)
        {
          pumpStations.Or(myPumpStations);
        }
        else if (player == oppID)
        {
          pumpStations.Or(oppPumpStations);
        }
        if (Equal(pumpStations, empty))
        {
          return empty;
        }

        // get connected pump stations
        BitArray connectedPumpStations = new BitArray(length, false);
        BitArray waterAndTrenchTiles = new BitArray(length, false).Or(waterTiles).Or(trenchTiles);
        List<int> pumpStationIndeces = GetIndexes(pumpStations);
        foreach (int index in pumpStationIndeces)
        {
          // get current pump station
          BitArray currentPumpStation = GetPumpStation(pumpStations, index / height, index % height);
          if (Equal(currentPumpStation, empty))
          {
        continue;
          }

          // get starting points from current pump station's adjacency bitboard
          BitArray currentAdjacency = GetAdjacency(currentPumpStation).And(waterAndTrenchTiles);
          if (Equal(currentAdjacency, empty))
          {
        // remove current pump station from pump stations bitboard, continue
        pumpStations.Xor(currentPumpStation);
        continue;
          }
          List<int> startingPoints = GetIndexes(currentAdjacency);

          // get path from starting points to nearest connected glacier
          foreach (int start in startingPoints)
          {
        BitArray invalidTiles = new BitArray(length, false).Or(waterTiles).Or(trenchTiles).Or(iceCaps).Xor(full);
        List<Node> path = AStar.route(GetX(start), GetY(start), iceCaps, false, invalidTiles);

        // if a path exists and ice cap is still producing, add current pump station to connected pump stations bitboard, go to next pump station
        if (path.Count != 0)
        {
          bool validConnected = true;
          foreach (Tile tile in BaseAI.tiles)
          {
            if (tile.X == path[path.Count - 1].x && tile.Y == path[path.Count - 1].y)
            {
              if (tile.WaterAmount <= 1)
              {
                validConnected = false;
              }
              break;
            }
          }
          if (validConnected)
          {
            connectedPumpStations.Or(currentPumpStation);
            break;
          }
        }
          }

          // remove current pump station from pump stations bitboard
          pumpStations.Xor(currentPumpStation);
        }

        return connectedPumpStations;
    }
开发者ID:austingantner,项目名称:MegaMinerAI12-Mars,代码行数:76,代码来源:BitBoard.cs


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