Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Bit Array Class Operations (Not, XOR, Is synchronized, Set All) in VB and C# (.net 2.0).Part2

Author: Zunnair
Download Source Code : 912_control.zip

In this simple article you will learn that how we can perform different operations of bit array class object in VB and C# .net 2.0.

 

XOR Operation:
XOR operation compares bits of one object with the other. If bits of both objects are same like true and true or false and false then result is false. If both bits are different like false and true then answer is true. For this purpose bit array class provides us a function named Xor. Function takes object of bit array class performs xor operation and returns the bit array class object.
To demonstrate make a window application. Drag list box and one button on form.
Now write the following code on Button click event:
C#
private void btn_Xor_Click(object sender, EventArgs e)
        {
            obj3 = obj1.Xor(obj2);
            int i = 0;
            bool b;
            listBox1.Items.Clear();
            for (i = 0; i < 5; i++)
            {
                b = obj3.Get(i);
                listBox1.Items.Add(b);
            }
        }
VB
This simple code performs XOR operation.
Not Operation:
Not operation inverts the current bits of object. If bit is true it makes it false and if bit is false then makes it true. For this purpose bit array class provides us a function named not. Function does not take any parameter, performs not operation on the values of object through which it is called and returns the bit array class object.
To demonstrate make a window application. Drag list box and one button on form.
Now write the following code on Button click event:
C#
private void btn_not_Click(object sender, EventArgs e)
        {
            obj3 = obj1.Not();
            int i = 0;
            bool b;
            listBox1.Items.Clear();
            for (i = 0; i < 5; i++)
            {
                b = obj3.Get(i);
                listBox1.Items.Add(b);
            }
 
        }
VB
This simple code performs not operation.
Set All:
If you want to set all the bits to a specific value for this purpose we have a function named set all. Function takes Boolean value as parameter and returns nothing.
To demonstrate make a window application. Drag one button on form.
Now write the following code on Button click event:
C#
private void btn_SetAll_Click(object sender, EventArgs e)
        {
            bool b;
            b = false;
            obj1.SetAll(b);
            MessageBox.Show("All bits set");
        }
VB
This is the simple code to set all bits.
Is Synchronized:
If you want to check that access to bit array is synchronized or not for this purpose we have a property named is synchronized. This property returns Boolean value. If true then synchronized else not.
To demonstrate make a window application. Drag one button on form.
Now write the following code on Button click event:
C#
private void txt_IsSync_Click(object sender, EventArgs e)
        {
            bool b;
            string str;
            b = obj1.IsSynchronized;
            str = b.ToString();
           MessageBox.Show(str);
        }
VB
This is simple code to get the value which tells that array is synchronized or not.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Devasp BitArray Application";
            arr.SetValue(true, 0);
            arr.SetValue(true, 1);
            arr.SetValue(true, 2);
            arr.SetValue(true, 3);
            arr.SetValue(true, 4);
            arr1.SetValue(false, 0);
           arr1.SetValue(false, 1);
            arr1.SetValue(false, 2);
            arr1.SetValue(false, 3);
            arr1.SetValue(false, 4);
            obj1 = new System.Collections.BitArray(arr);
            obj2= new System.Collections.BitArray(arr1);
            obj3 = new System.Collections.BitArray(arr2);
            int i = 0;
            for(i=0;i<5;i++)
                listBox1.Items.Add(arr.GetValue(i));
            for (i = 0; i < 5; i++)
                listBox1.Items.Add(arr1.GetValue(i));
           
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.Text = "Devasp BitArray Application"
        arr.SetValue(True, 0)
        arr.SetValue(True, 1)
        arr.SetValue(True, 2)
        arr.SetValue(True, 3)
        arr.SetValue(True, 4)
        arr1.SetValue(False, 0)
        arr1.SetValue(False, 1)
        arr1.SetValue(False, 2)
        arr1.SetValue(False, 3)
        arr1.SetValue(False, 4)
        obj1 = New System.Collections.BitArray(arr)
        obj2 = New System.Collections.BitArray(arr1)
        obj3 = New System.Collections.BitArray(arr2)
        Dim i As Integer = 0
        For i = 0 To 4
            listBox1.Items.Add(arr.GetValue(i))
        Next
        For i = 0 To 4
            listBox1.Items.Add(arr1.GetValue(i))
 
        Next
    End Sub
This simple article tells that we can perform different operations on bit array class object in VB and C# .net 2.0.
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Bit Array Class Operations (And, Or, Count, Length) in VB and C# (.net 2.0).Part1

Disclaimer - Privacy
© 2002-2017 DevASP.net