Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Bit Array in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 151
    Comment on it

    The Bit Array class represent compact bit of values mainly represented with 1 or 0 or you can say true or false.

     

     

     

    It is used when you want to store bits but don't know the size in advance.

     

     

    You can access items using its index which starts with zero.

     

    Properties of Bit Array

     

    Property Description
    Count Count the number of elements in the array
    IsReadOnly Check whether the value is read only
    Item It will set or get the value of the array.
    Length Gets or sets the number of elements in the BitArray.

     

     

    Methods of Bit Array:

    Sr.No. Methods
    1 public BitArray And(BitArray value);

    It will do the AND operation in the Bit Array

    2 public bool Get(int index);

    It will find out the bit at the specific position from the bit array

    3 public BitArray Not();

    It acts like an inverter that makes the true value false and false value true

    4 public BitArray Or(BitArray value);

    It will perform the OR operation in the bit array

    5 public void Set(int index, bool value);

    It will set the particular value at specific position

    6 public void SetAll(bool value);

    It will set all the value at specific position

    7 public BitArray Xor(BitArray value);

    It will do the XOR operation into the bit array

     

     class Program
       {
          static void Main(string[] args)
          {
             //creating two  bit arrays of size 8
             BitArray ba1 = new BitArray(8);
             BitArray ba2 = new BitArray(8);
             byte[] a = { 60 };
             byte[] b = { 13 };
             
             //storing the values 60, and 13 into the bit arrays
             ba1 = new BitArray(a);
             ba2 = new BitArray(b);
             
             //content of ba1
             Console.WriteLine("Bit array ba1: 60");
             
             for (int i = 0; i < ba1.Count; i++)
             {
                Console.Write(ba1[i]);
             }
             Console.WriteLine();
             
             
             //content of ba2
             Console.WriteLine("Bit array ba2 after OR operation: 61");
             
             for (int i = 0; i < ba2.Count; i++)
             {
                Console.Write(ba2[i]);
             }
             Console.WriteLine();
             
             Console.ReadKey();
            }
        }

     

     

     

    In this function we are declaring the array and after declaring it we are storing another values into it dynamically.

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: