Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,023 questions

51,974 answers

573 users

How to create a bitset in C#

1 Answer

0 votes
using System;
using System.Collections;

class Program
{
    static void Main()
    {
        // Create a BitArray with a size of 8 bits
        BitArray bitArray = new BitArray(8);

        // Set some bits
        bitArray[0] = true;  // Set the first bit
        bitArray[3] = true;  // Set the fourth bit

        // Print the BitArray
        Console.WriteLine("BitArray:");
        PrintBitArray(bitArray);

        bitArray.SetAll(false);  // Set all bits to false
        bitArray.Set(2, true);   // Set the third bit to true

        // Print the modified BitArray
        Console.WriteLine("Modified BitArray:");
        PrintBitArray(bitArray);
    }

    static void PrintBitArray(BitArray bitArray) {
        for (int i = 0; i < bitArray.Length; i++) {
            Console.Write(bitArray[i] ? "1" : "0");
        }
        Console.WriteLine();
    }
}



/*
run:
 
BitArray:
10010000
Modified BitArray:
00100000
 
*/

 



answered May 7, 2025 by avibootz

Related questions

1 answer 38 views
1 answer 108 views
108 views asked May 7, 2025 by avibootz
1 answer 99 views
1 answer 102 views
102 views asked May 7, 2025 by avibootz
1 answer 107 views
107 views asked May 7, 2025 by avibootz
2 answers 109 views
2 answers 83 views
...