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


C# BitArray.Set方法代码示例

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


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

示例1: ToArray

        internal byte[] ToArray()
        {
            var list = new List<byte>();
            list.Add(ExtensionIntroducer);
            list.Add(GraphicControlLabel);
            list.Add(BlockSize);

            //Packed fields
            var bitArray = new BitArray(8);

            //Reserved for future use. Hahahaha. Yeah...
            bitArray.Set(0, false);
            bitArray.Set(1, false);
            bitArray.Set(2, false);

            var pixelBits = GifMethods.ToBitValues((int)DisposalMethod);

            bitArray.Set(3, pixelBits[0]);
            bitArray.Set(4, pixelBits[1]);
            bitArray.Set(5, pixelBits[2]);

            //User Input Flag.
            bitArray.Set(6, false);

            //Transparent Color Flag, uses tranparency?
            bitArray.Set(7, HasTransparency);

            list.Add(GifMethods.ConvertToByte(bitArray));
            list.AddRange(BitConverter.GetBytes(Delay));
            list.Add(TransparentIndex);
            list.Add(Terminator);

            return list.ToArray();
        }
开发者ID:dbremner,项目名称:ScreenToGif,代码行数:34,代码来源:GraphicExtension.cs

示例2: ToArray

        internal byte[] ToArray()
        {
            var list = new List<byte>();
            list.AddRange(BitConverter.GetBytes(Width));
            list.AddRange(BitConverter.GetBytes(Height));

            //Packed fields, 1 byte
            var bitArray = new BitArray(8);
            bitArray.Set(0, HasGlobalColorTable);

            //Color resolution: 111 = (8 bits - 1)
            //Color depth - 1
            //Global colors count = 2^color depth
            var pixelBits = GifMethods.ToBitValues(GlobalColorTableSize);

            bitArray.Set(1, pixelBits[0]);
            bitArray.Set(2, pixelBits[1]);
            bitArray.Set(3, pixelBits[2]);

            //Sort flag (for the global color table): 0
            bitArray.Set(4, IsSorted);

            //Size of the Global Color Table (Zero, if not used.): 
            var sizeInBits = GifMethods.ToBitValues(GlobalColorTableSize);

            bitArray.Set(5, sizeInBits[0]);
            bitArray.Set(6, sizeInBits[1]);
            bitArray.Set(7, sizeInBits[2]);

            list.Add(GifMethods.ConvertToByte(bitArray));
            list.Add(BackgroundIndex); //Background color index, 1 byte
            list.Add(0); //Pixel aspect ratio - Assume 1:1, 1 byte

            return list.ToArray();
        }
开发者ID:dbremner,项目名称:ScreenToGif,代码行数:35,代码来源:LogicalScreenDescriptor.cs

示例3: Increment

 public static bool Increment(BitArray bits, int size)
 {
     int i = size - 1;
     while (i >= 0 && bits.Get(i))
     {
         bits.Set(i--, false);
     }
     if (i < 0)
     {
         return false;
     }
     bits.Set(i, true);
     return true;
 }
开发者ID:ronnyMakhuddin,项目名称:SharperNLP,代码行数:14,代码来源:Util.cs

示例4: BitArray_SetTest

            public static void BitArray_SetTest()
            {
                // []  Set true to true, true to false
                // []  Set false to false and false to true is covered in BitArray_GetTest() above
                BitArray ba2 = new BitArray(6, true);

                ba2.Set(0, true);
                ba2.Set(1, false);
                ba2.Set(2, true);
                ba2.Set(5, true);

                Assert.True(ba2.Get(0)); //"Err_7! Expected ba4.Get(0) to be true"
                Assert.False(ba2.Get(1)); //"Err_8! Expected ba4.Get(1) to be false"
                Assert.True(ba2.Get(2)); //"Err_9! Expected ba4.Get(2) to be true"
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:15,代码来源:BitArray_GetSetTests.cs

示例5: GetBits

        /// <summary>
        /// Get the bits from a Base32 encoded string.
        /// </summary>
        /// <param name="base32text">A Base32 encoded string to decode into a byte array.</param>
        /// <returns>An array of bits from the resulting byte array.</returns>
        public static BitArray GetBits(string base32text)
        {
            char[] input = base32text.ToLower().ToCharArray();

            /*
             * Base32 = 5 bits in a character
             * Length = number of characters * 5 bits per character
             */

            int bitsIn32 = 5;
            int resultsLength = input.Length * bitsIn32;

            // Use the length to create the resulting bits array
            BitArray results = new BitArray(resultsLength, false);

            int index = 0;

            for (int i = 0; i < input.Length; i++)
            {
                char c = input[i];
                int value = Array.IndexOf(encodingTable, c);
                if (value == -1) throw new ApplicationException("The Base32 encoded string contains invalid characters.");

                BitArray bits = new BitArray(new byte[] { Convert.ToByte(value) });

                for (int x = 0; x < bitsIn32; x++)
                {
                    results.Set(index, bits.Get(x));
                    index++;
                }
            }

            return results;
        }
开发者ID:SimWitty,项目名称:SimWitty,代码行数:39,代码来源:Base32.cs

示例6: ToBitArray

		public BitArray ToBitArray()
		{
			BitArray result = new BitArray(array.Length);
			for(int i = 0 ; i < array.Length ; i++)
				result.Set(i, array.Get(i));
			return result;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:7,代码来源:BitWriter.cs

示例7: Chromosome

 public Chromosome(int length)
 {
     Data = new BitArray(length);
       Random rand = new Random();
       for(int i = 0; i<length; i++)
     Data.Set(i,rand.Next(2) == 1);
 }
开发者ID:ThomasHoest,项目名称:Assault,代码行数:7,代码来源:GA.cs

示例8: SieveOfEratosthenes

        public long[] SieveOfEratosthenes()
        {
            var sieveBound = (_limit - 1) / 2;
            var upperSqrt = ((int)Math.Sqrt(_limit) - 1) / 2;

            var primeBits = new BitArray(sieveBound + 1, true);

            for (var i = 1; i <= upperSqrt; i++)
            {
                if (primeBits.Get(i))
                {
                    for (var j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1)
                    {
                        primeBits.Set(j, false);
                    }
                }
            }

            var capacity = (int)(_limit / (Math.Log(_limit) - 1.08366));
            var numbers = new List<long>(capacity) { 2 };
            for (var i = 1; i <= sieveBound; i++)
            {
                if (primeBits.Get(i))
                    numbers.Add(2 * i + 1);
            }

            return numbers.ToArray();
        }
开发者ID:wrparra,项目名称:ProjectEuler,代码行数:28,代码来源:PrimeNumbers.cs

示例9: BitArray_GetTest

            public static void BitArray_GetTest()
            {
                BitArray ba2 = new BitArray(6, false);

                ba2.Set(0, true);
                ba2.Set(1, false);
                ba2.Set(2, true);
                ba2.Set(5, true);

                Assert.True(ba2.Get(0)); //"Err_1! Expected ba4.Get(0) to be true"
                Assert.False(ba2.Get(1)); //"Err_2! Expected ba4.Get(1) to be false"
                Assert.True(ba2.Get(2)); //"Err_3! Expected ba4.Get(2) to be true"
                Assert.False(ba2.Get(3)); //"Err_4! Expected ba4.Get(3) to be false"
                Assert.False(ba2.Get(4)); //"Err_5! Expected ba4.Get(4) to be false"
                Assert.True(ba2.Get(5)); //"Err_6! Expected ba4.Get(5) to be true"
            }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:16,代码来源:BitArray_GetSetTests.cs

示例10: Mutate

 /// <summary>
 /// Mutates a gene by bitwise mutation.
 /// </summary>
 /// <param name="gene"></param>
 /// <returns></returns>
 public static Gene Mutate(Gene gene)
 {
     if ( gene is BinaryGene )
     {
         BinaryGene g = (BinaryGene) gene.Clone();
         g.Value = !(BinaryGene)gene;
         return g;
     }
     else if ( gene is DoubleGene )
     {
         DoubleGene g = (DoubleGene) gene.Clone();
         byte[] bytes = BitConverter.GetBytes(g.Value);
         BitArray ba = new BitArray(bytes);
         int p = Utils.Rand.Next( ba.Length );
         ba.Set(p, !ba[p]);
         ba.CopyTo(bytes, 0);
         g.Value = BitConverter.ToDouble(bytes,0);
         return g;
     }
     else if ( gene is IntegerGene )
     {
         IntegerGene g = (IntegerGene) gene.Clone();
         byte[] bytes = BitConverter.GetBytes(g.Value);
         BitArray ba = new BitArray(bytes);
         int p = Utils.Rand.Next( ba.Length );
         ba.Set(p, !ba[p]);
         ba.CopyTo(bytes, 0);
         g.Value = BitConverter.ToInt32(bytes,0);
         return g;
     }
     return (Gene) gene.Clone(); // default
 }
开发者ID:mykwillis,项目名称:genX,代码行数:37,代码来源:Mutation.cs

示例11: ESieve

        public static int[] ESieve(int upperLimit)
        {
            int sieveBound = (int)(upperLimit - 1) / 2;
            int upperSqrt = ((int)Math.Sqrt(upperLimit) - 1) / 2;

            BitArray PrimeBits = new BitArray(sieveBound + 1, true);

            for (int i = 1; i <= upperSqrt; i++)
            {
                if (PrimeBits.Get(i))
                {
                    for (int j = i * 2 * (i + 1); j <= sieveBound; j += 2 * i + 1)
                    {
                        PrimeBits.Set(j, false);
                    }
                }
            }

            List<int> numbers = new List<int>((int)(upperLimit / (Math.Log(upperLimit) - 1.08366)));
            numbers.Add(2);

            for (int i = 1; i <= sieveBound; i++)
            {
                if (PrimeBits.Get(i))
                {
                    numbers.Add(2 * i + 1);
                }
            }

            return numbers.ToArray();
        }
开发者ID:dstites,项目名称:Project-Euler,代码行数:31,代码来源:Utilities.cs

示例12: next_ServerClick

        protected void next_ServerClick(object sender, EventArgs e)
        {
            user u = new user();
            u.user_id = (int)Session["id"];
            u = os.getUserById(u);
            int seat_num = (int)Session["seat_num"];

            o.SSR = this.SSR.Value ;
            o.type = type;

            FlightService fs = new FlightService();
            String plane_type_name = searchF.plane.plane_type.name;
            BitArray seat = new BitArray(20);
            seat.SetAll(false);
            seat.Set(seat_num,true);
            o.seat = OrderService.BitArrayToByteArray(seat);

            if ( (o = os.generate(u, searchF, o, seat_num)) != null)
            {
                Session["new_order"] = o;
                Server.Transfer("payment.aspx");
            }
            else
            {
                ShowPopUpMsg("Seat is book by others!");
            }
        }
开发者ID:lao605,项目名称:FYXFlightSystem,代码行数:27,代码来源:enter-personal-information.aspx.cs

示例13: Run

        //Runs the algoritm for number of iterations
        public override void Run(Configuration config)
        {
            log = new RandomLogSpecification(data.DataFileName, config.RandomSeed, config.NumberOfRuns, config.PenaltyCoefficient);
            solution = new SolutionSpecification();

            BitArray routerswitches = new BitArray((int)data.RouterCount);
            double highestfitness = 0.0;
            BitArray best = new BitArray((int)data.RouterCount);
            for(int i = 0; i < config.NumberOfRuns; i++)
            {
                routerswitches = new BitArray((int)data.RouterCount);
                int numbertoswitch = randomgenerator.Next((int)data.RouterCount);
                for(int j = 0; j < numbertoswitch; j++)
                {
                    int switching;
                    while(routerswitches.Get(switching = randomgenerator.Next((int)data.RouterCount)) == true);
                    routerswitches.Set(switching, true);
                }

                double fitness = FitnessEvaluation(data.NetworkPaths, routerswitches, numbertoswitch, config.PenaltyCoefficient);

                if(fitness > highestfitness)
                {
                    ((RandomLogSpecification)log).AddEvaluation(i, fitness);
                    highestfitness = fitness;
                    best = (BitArray)routerswitches.Clone();
                }
            }

            solution.RoutersTurnedOff = ExtensionMethods.ConvertBitArrayToOffRouterNumbers(best, data.HostCount);
        }
开发者ID:addiem7c5,项目名称:CS348,代码行数:32,代码来源:RandomSearch.cs

示例14: AjustLength

 private void AjustLength(BitArray array)
 {
     int length = array.Length;
     int newLength = array.Length + 1;
     if ((newLength & 512) > 448)
     {
         newLength += 64;
     }
     newLength = ((newLength >> 9) << 9) | 448;
     array.Length = newLength;
     array.Set(length, true);
     for (int i = length + 1; i < newLength; i++)
     {
         array.Set(length, false);
     }
 }
开发者ID:huangcd,项目名称:HuangcdLib,代码行数:16,代码来源:MD5Encrypt.cs

示例15: DecodeHiddenMessage

        public AudioFile DecodeHiddenMessage(AudioFile containerAudioFile)
        {
            var hiddenBitsPerSample = containerAudioFile.waveFile.bitsPerSample / CHANGING_SAMPLES_FACTOR;

            var hiddenMessageBits = new BitArray((int)(containerAudioFile.waveFile.samples.Length * hiddenBitsPerSample));

            var maxNumberOfDecodingSteps = containerAudioFile.waveFile.samples.Length;

            for (int i = 0; i < maxNumberOfDecodingSteps; i++)
            {
                var uintValue = containerAudioFile.waveFile.samples[i];
                var intFromBitsToRead = uintValue.GetLastNBitsIntValue((int) hiddenBitsPerSample);

                var hiddenIntBits = new BitArray(new[] { intFromBitsToRead }).GetBitArrayFromBitArrayRange(0, (int) hiddenBitsPerSample);

                for(int j = 0; j < hiddenIntBits.Length; j++)
                {
                    hiddenMessageBits.Set(i * (int) hiddenBitsPerSample + j, hiddenIntBits[j]);
                }
            }

            containerAudioFile.waveFile.Save();

            var messageBytes = new byte[hiddenMessageBits.Count];
            hiddenMessageBits.CopyTo(messageBytes, 0);

            return new AudioFile(containerAudioFile.bytes, messageBytes);
        }
开发者ID:Rybzor,项目名称:Stego,代码行数:28,代码来源:WaveCoding.cs


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