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


C# Collections.BitArray类代码示例

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


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

示例1: AsyncResult

 internal AsyncResult(string message, int ftpCode, int result)
 {
     m_result = new BitArray(3);
     m_message = message;
     m_ftpResponse = ftpCode;
     m_result[result] = true;
 }
开发者ID:avs009,项目名称:gsf,代码行数:7,代码来源:AsyncResult.cs

示例2: MakeADTree

        private ADNode MakeADTree(int i, BitArray recordNums, int depth, Varset variables)
        {
            // since this is index i, there are (variableCount - i) remaining variables.
            // therefore, it will have that many children
            int count = 0;
            for(int idx = 0; idx < recordNums.Count; idx++)
            {
                if (recordNums[idx])
                {
                    count += 1;
                }
            }
            ADNode adn = new ADNode(network.Size() - i, count);

            // check if we should just use a leaf list
            if (adn.Count < rMin)
            {
                BitArray leafList = new BitArray(recordNums);
                adn.LeafList = leafList;
                return adn;
            }

            // for each of the remaining variables
            for (int j = i; j < network.Size(); j++)
            {
                // create a vary node
                variables.Set(j, true);
                Varset newVariables = new Varset(variables);
                VaryNode child = MakeVaryNode(j, recordNums, depth, newVariables);
                adn.SetChild(j - i, child);
            }

            return adn;
        }
开发者ID:shskwmt,项目名称:UrlearningCS,代码行数:34,代码来源:AdTree.cs

示例3: Mutate

        /*
        // It mutates the Chromosome
        //
        // @input probability is a double >=0 and <=100
        */
        public bool Mutate(double probability)
        {
            if (probability < 0) probability = 0;
            if (probability > 100) probability = 100;
            bool isMutated = false;
            for (int counter = 0; counter<nucleotideList.Count; counter++)
            {
                byte myByte = nucleotideList[counter];
                //var bits = new BitArray(myByte);
                var bits = new BitArray(new byte[] { myByte });
                //Cycle for change the single bit of the DNA
                for (int i = 0; i < bits.Length; i++)
                {
                    Random r = new Random(Guid.NewGuid().GetHashCode());
                    if (r.NextDouble() < (probability / 100))
                    {
                        bits[i] = !bits[i]; //the mutation switch the bit
                        isMutated = true;
                    }
                }
                //From BitArray to Byte[]
                byte[] ret = new byte[bits.Length / 8];
                bits.CopyTo(ret, 0);

                //Assigning the new Byte[] to the nucleotide
                nucleotideList[counter] = ret[0];
            }
                
            return isMutated;
        }
开发者ID:mpatacchiola,项目名称:evoface,代码行数:35,代码来源:Chromosome.cs

示例4: Setup

        private void Setup()
        {
            // Fill Bit arrays

            chka = new[] {
                flag_0001,flag_0002,flag_0003,flag_0004,flag_0005,
                flag_2237,flag_2238,flag_2239,
                flag_0115,flag_0963, // Mewtwo
                flag_0114,flag_0790, // Zygarde
                flag_0285,flag_0286,flag_0287,flag_0288,flag_0289, // Statuettes
                flag_0290,flag_0291,flag_0292,flag_0293,flag_0294, // Super Unlocks
                flag_0675, // Chatelaine 50
                flag_2546, // Pokedex
            };
            byte[] data = new byte[0x180];
            Array.Copy(Main.SAV.Data, Main.SAV.EventFlag, data, 0, 0x180);
            BitArray BitRegion = new BitArray(data);
            BitRegion.CopyTo(flags, 0);

            // Setup Event Constant Editor
            CB_Stats.Items.Clear();
            for (int i = 0; i < Constants.Length; i += 2)
            {
                CB_Stats.Items.Add($"0x{i.ToString("X3")}");
                Constants[i / 2] = BitConverter.ToUInt16(Main.SAV.Data, Main.SAV.EventConst + i);
            }
            CB_Stats.SelectedIndex = 0;

            // Populate Flags
            setup = true;
            popFlags();
        }
开发者ID:Bluestar012,项目名称:PKHeX,代码行数:32,代码来源:SAV_EventFlagsXY.cs

示例5: CompleteGraph

 public CompleteGraph(int n)
 {
     if (n <= 0)
         throw new ArgumentOutOfRangeException("[CompleteGraph Constructor] Input size of CompleteGraph must be positive");
     this.nodes = n;
     this.edges = new BitArray(n * (n - 1) / 2);
 }
开发者ID:paulraff,项目名称:2016JointMeetings,代码行数:7,代码来源:CompleteGraph.cs

示例6: GetBoolArrayFromByte

 public static bool[] GetBoolArrayFromByte(byte[] bytes)
 {
     bool[] bools = new bool[bytes.Length * 8];
     BitArray bits = new BitArray(bytes);
     bits.CopyTo(bools, 0);
     return bools;
 }
开发者ID:remy22,项目名称:soundfingerprinting,代码行数:7,代码来源:ArrayUtils.cs

示例7: SlabAllocator

        public SlabAllocator(int pageSize, int pageCount)
        {
            _pageSize = pageSize;
            _totalSize = pageCount * pageSize;

            _allocationMap = new BitArray(pageCount);
        }
开发者ID:martindevans,项目名称:Earmark,代码行数:7,代码来源:SlabAllocator.cs

示例8: DoPrevSetBit

 internal virtual void DoPrevSetBit(BitArray a, LongBitSet b)
 {
     int aa = a.Count + Random().Next(100);
     long bb = aa;
     do
     {
         //aa = a.PrevSetBit(aa-1);
         aa--;
         while ((aa >= 0) && (!a.SafeGet(aa)))
         {
             aa--;
         }
         if (b.Length() == 0)
         {
             bb = -1;
         }
         else if (bb > b.Length() - 1)
         {
             bb = b.PrevSetBit(b.Length() - 1);
         }
         else if (bb < 1)
         {
             bb = -1;
         }
         else
         {
             bb = bb >= 1 ? b.PrevSetBit(bb - 1) : -1;
         }
         Assert.AreEqual(aa, bb);
     } while (aa >= 0);
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:31,代码来源:TestLongBitSet.cs

示例9: GetBitmapData

		/// <summary>
		/// get the B&W 1BPP bitmap for a bmp file 
		/// </summary>
		/// <param name="bmpFileName">
		/// </param>
		/// <returns>
		/// </returns>
        private static BitmapDotData GetBitmapData(string bmpFileName)
        {
            Image img = new Bitmap(bmpFileName); 
            using (var bitmap = new Bitmap(img))// (Bitmap)Bitmap.FromFile(bmpFileName))
            {
                var threshold = 127;
                var index = 0;
                var dimensions = bitmap.Width * bitmap.Height;
                var dots = new BitArray(dimensions);

                for (var y = 0; y < bitmap.Height; y++)
                {
                    for (var x = 0; x < bitmap.Width; x++)
                    {
                        var color = bitmap.GetPixel(x, y);
                        var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
                        dots[index] = (luminance < threshold);
                        index++;
                    }
                }

                return new BitmapDotData()
                    {
                        Dots = dots,
                        Height = bitmap.Height,
                        Width = bitmap.Width
                    };
            }
        }
开发者ID:andrejpanic,项目名称:win-mobile-code,代码行数:36,代码来源:BitimageClass.cs

示例10: ArrayFieldOfView

 public ArrayFieldOfView(IFovBoard<IHex> board)
 {
     _isOnboard = h => board.IsOnboard(h);
     _fovBacking = new BitArray[board.MapSizeHexes.Width];
     for (var i = 0; i < board.MapSizeHexes.Width; i++)
         _fovBacking[i] = new BitArray(board.MapSizeHexes.Height);
 }
开发者ID:VaultDwe11er,项目名称:Warhammer-Campaign,代码行数:7,代码来源:FieldOfView.cs

示例11: TM1638ButtonsMessageReader

 private void TM1638ButtonsMessageReader(IList<int> messageData)
 {
     int readPos = 1;
     for (int u = 1; u <= this.numberUnits; u++)
     {
         if (this.tm1640Units[u - 1])
         {
             continue;
         }
         this.buttonsRead = messageData[readPos++];
         if (this.buttonsRead != -1)
         {
             this.butByte[0] = Convert.ToByte(this.buttonsRead);
             this.buttons = new BitArray(this.butByte);
             for (var i = 0; i < Constants.NumberButtonsOnTm1638; i++)
             {
                 if (this.buttons[i])
                 {
                     if (this.ButtonPress == null) throw new ArgumentNullException();
                     ButtonPressEventHandler temp = this.ButtonPress;
                     if (temp != null)
                     {
                         temp(u, i+1);
                     }
                 }
             }
         }
     }
 }
开发者ID:tobig82,项目名称:iRduino,代码行数:29,代码来源:ArduinoMessagesReceiving.cs

示例12: GetCombines

        static IList<string> GetCombines(string str)
        {
            var result = new List<string>();
            var arr = str.Split(',');
            var numItem = arr.Length;

            for (int i = 1; i <= Math.Pow(2, numItem); i++)
            {
                string temp = null;
                BitArray b = new BitArray(new int[] { i });
                for (int j = 0; j < numItem; j++)
                {
                    if (b[j])
                    {
                        if (temp != null)
                        {
                            temp += ",";
                        }

                        temp += arr[j];
                    }
                }

                if (!string.IsNullOrEmpty(temp))
                {
                    result.Add(temp);
                }
            }

            return result;
        }
开发者ID:cupidshen,项目名称:misc,代码行数:31,代码来源:Program.cs

示例13: GetByteArrayFromBool

 /// <summary>
 ///   Get bytes array from Boolean values.
 /// </summary>
 /// <param name = "array">Array to be packed</param>
 /// <returns>Bytes array</returns>
 public static byte[] GetByteArrayFromBool(bool[] array)
 {
     BitArray b = new BitArray(array);
     byte[] bytesArr = new byte[array.Length / 8];
     b.CopyTo(bytesArr, 0);
     return bytesArr;
 }
开发者ID:eugentorica,项目名称:soundfingerprinting,代码行数:12,代码来源:ArrayUtils.cs

示例14: WriteBitArray

        private static void WriteBitArray(ObjectWriter writer, BitArray bitArray)
        {
            // Our serialization format doesn't round-trip bit arrays of non-byte lengths
            Contract.ThrowIfTrue(bitArray.Length % 8 != 0);

            writer.WriteInt32(bitArray.Length / 8);

            // This will hold the byte that we will write out after we process every 8 bits. This is
            // LSB, so we push bits into it from the MSB.
            byte b = 0;

            for (var i = 0; i < bitArray.Length; i++)
            {
                if (bitArray[i])
                {
                    b = (byte)(0x80 | b >> 1);
                }
                else
                {
                    b >>= 1;
                }

                if ((i + 1) % 8 == 0)
                {
                    // End of a byte, write out the byte
                    writer.WriteByte(b);
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:BloomFilter_Serialization.cs

示例15: ExtendToSizeRight

 /// <summary>
 /// aaa -> 000aaa
 /// </summary>
 /// <param name="to">Reference to array to put the result</param>
 /// <param name="bitArray">Array from where to put</param>
 /// <param name="p">Size of the new array</param>
 private void ExtendToSizeRight(ref BitArray to, BitArray bitArray, int p)
 {
     if (to == null)
         to = new BitArray(p, false);
     for (int i = 0; i < bitArray.Length; i++)
         to[i] = bitArray[i];
 }
开发者ID:Frosne,项目名称:SShA,代码行数:13,代码来源:Program.cs


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