static void Main(string[] args)
        {
            BitArray64 number = new BitArray64(7);

            // print bits of the ulong number
            foreach (var bit in number)
            {
                Console.Write(bit);
            }
            Console.WriteLine();

            // make second BitArray
            BitArray64 number2 = new BitArray64(7);

            Console.WriteLine(number.Equals(number2));

            // indexer starts from young bits
            Console.WriteLine(number[2]);
            // print hash code
            Console.WriteLine(number.GetHashCode());

            // change bit
            number[4] = 1;
            // print the changed number and his bits
            Console.WriteLine(number.Number);
            foreach (var bit in number)
            {
                Console.Write(bit);
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
    // Define a class BitArray64 to hold 64 bit values inside an ulong value.
    // Implement IEnumerable<int> and Equals(…), GetHashCode(), [], == and !=.
    internal static void Main()
    {
        // Let's use int.MaxValue (32 one's) to set the BitArray64
        BitArray64 bitArray1 = new BitArray64(int.MaxValue);

        // Use IEnumerable to foreach the elements in the BitArray64
        Console.Write("bitArray1: ");
        foreach (var bit in bitArray1)
        {
            Console.Write(bit);
        }

        // Use BitArray64.ToString to print the second bitarray
        BitArray64 bitArray2 = new BitArray64(int.MaxValue - 1);
        Console.WriteLine("\nbitArray2: {0}", bitArray2);

        // Test BitArray64.Equals, ==, !=
        Console.WriteLine();
        Console.WriteLine("bitArray1.Equals(bitArray2) -> {0}", bitArray1.Equals(bitArray2));
        Console.WriteLine("(bitArray1 == bitArray2) -> {0}", bitArray1 == bitArray2);
        Console.WriteLine("(bitArray1 != bitArray2) -> {0}", bitArray1 != bitArray2);

        // Test BitArray64.GetHashCode
        Console.WriteLine();
        Console.WriteLine("bitArray1 HashCode: {0}", bitArray1.GetHashCode());
        Console.WriteLine("bitArray2 HashCode: {0}", bitArray2.GetHashCode());

        // Test indexers
        Console.WriteLine();
        Console.WriteLine("bitArray1[0] = {0}", bitArray1[0]);
        Console.WriteLine("bitArray2[0] = {0}", bitArray2[0]);
    }
        static void Main()
        {
            var number1 = new BitArray64(22L);
            var number2 = new BitArray64(33L);

            number2[62] = 1;

            Console.WriteLine("number2[62] = {0}", number2[62]);
            Console.WriteLine();

            foreach (var bit in number1)
            {
                Console.Write(bit);
            }
            Console.WriteLine();
            Console.WriteLine(number2);

            Console.WriteLine();

            Console.WriteLine(number1.GetHashCode());
            Console.WriteLine(number2.GetHashCode());

            Console.WriteLine();

            Console.WriteLine("number1 == number2 : {0}", number1 == number2);
            Console.WriteLine("number1 != number2 : {0}", number1 != number2);
            Console.WriteLine("number1.Equals(number1) : {0}", number1.Equals(number1));
            Console.WriteLine("number1.Equals(number2) : {0}", number1.Equals(number2));
        }
Exemplo n.º 4
0
        static void Main()
        {
            //creating arrays
            BitArray64 firstBitArray = new BitArray64(27641465162362435);
            BitArray64 secondBitArray = new BitArray64(45765454765);

            //printing and comparing arrays
            Console.WriteLine("First array: ");
            Console.WriteLine(new string('-', 30));
            PrintArray(firstBitArray);
            Console.WriteLine("Value at index 5 is: {0}", firstBitArray[5]);
            Console.WriteLine("Hash Code: {0}", firstBitArray.GetHashCode());

            Console.WriteLine();
            Console.WriteLine("Second array: ");
            Console.WriteLine(new string('-', 30));
            PrintArray(secondBitArray);
            Console.WriteLine("Value at index 9 is: {0}", secondBitArray[9]);
            Console.WriteLine("Hash Code: {0}", secondBitArray.GetHashCode());

            var areEqual = firstBitArray == secondBitArray;
            Console.WriteLine();
            Console.WriteLine("First Array  == Second Array? {0}", areEqual);
           

        }
Exemplo n.º 5
0
 static void Main()
 {
     ulong number = 5;
     BitArray64 bit64 = new BitArray64(number);
     // Index test
     Console.WriteLine("Index test:");
     bit64[62] = 1;
     Console.WriteLine(bit64.ToString());
     //Console.WriteLine();
     //Equals method test
     Console.WriteLine("Equals method test");
     Console.WriteLine("7 equals 7 = {0}", bit64.Equals(new BitArray64(7ul)));
     Console.WriteLine("7 equals 9 = {0}", bit64.Equals(new BitArray64(9ul)));
     Console.WriteLine();
     //GetHashCode() test
     Console.WriteLine("GetHashCode() = {0}", bit64.GetHashCode());
     Console.WriteLine();
     // == and != test
     Console.WriteLine("== and != test");
     Console.WriteLine("7 == 7 = {0}", bit64 == new BitArray64(7ul));
     Console.WriteLine("7 != 7 = {0}", bit64 != new BitArray64(7ul));
     Console.WriteLine("7 != 9 = {0}", bit64 != new BitArray64(9ul));
     Console.WriteLine("7 == 9 = {0}", bit64 == new BitArray64(9ul));
     Console.WriteLine();
     //IEnumerable test
     Console.WriteLine("IEnumerable test");
     foreach (var bit in bit64)
     {
         Console.Write(bit);
     }
     Console.WriteLine();
 }
Exemplo n.º 6
0
        static void Main()
        {
            BitArray64 someNumber = new BitArray64(15);
            BitArray64 otherNumber = new BitArray64(150);
            //chech IEnumerable
            StringBuilder str = new StringBuilder();
            foreach (var bit in someNumber)
            {

                str.Append(bit);
            }
            string bitReperentation = str.ToString();

            char[] arrayBits = bitReperentation.ToCharArray();
            Array.Reverse(arrayBits);
            string finalBitRep = new string(arrayBits);
            finalBitRep = finalBitRep.TrimStart('0');
            Console.WriteLine(finalBitRep);
            //check equals and hashcode
            Console.WriteLine(someNumber.Equals(otherNumber));
            Console.WriteLine(someNumber.GetHashCode());
            Console.WriteLine(otherNumber.GetHashCode());

            //chech == and !=
            Console.WriteLine(someNumber==otherNumber);
            Console.WriteLine(someNumber!=otherNumber);
        }
    static void Main()
    {
        BitArray64 arr1 = new BitArray64(8UL);
        BitArray64 arr2 = new BitArray64(11239872323123421UL);

        Console.WriteLine("arr1 = {0}", arr1);
        Console.WriteLine("arr2 = {0}", arr2);

        Console.WriteLine("arr1 == arr2 -> {0}", arr1 == arr2);
        Console.WriteLine("arr1 != arr2 -> {0}", arr1 != arr2);

        Console.WriteLine("arr1[5] = {0}", arr1[5]);
        Console.WriteLine("Changing arr1[5] to 1:");
        arr1[5] = 1;
        Console.WriteLine("arr1[5] = {0}", arr1[5]);
        Console.WriteLine("arr1 is now {0}", arr1);

        Console.WriteLine("arr1 hash code = {0}", arr1.GetHashCode());
        Console.WriteLine("arr2 hash code = {0}", arr2.GetHashCode());

        Console.WriteLine("Show arr2 bits as '+' and '-' to test the foreach:");
        foreach (var bit in arr2)
        {
            if (bit == 1)
            {
                Console.Write('+');
            }
            else
            {
                Console.Write('-');
            }
        }
        Console.WriteLine();
    }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            BitArray64 bitArray = new BitArray64();
            for (int i = 0; i < 64; i++)
            {
                bitArray[i] = 0;
            }
            bitArray[2] = 1;
            bitArray[36] = 1;

            Console.WriteLine("Showing the array...");
            Console.WriteLine("Using foreach:");
            foreach (var num in bitArray)
            {
                Console.Write(num);
            }
            Console.WriteLine();

            IEnumerator enumerator = bitArray.GetEnumerator();

            Console.WriteLine("Using enumerator:");
            while (enumerator.MoveNext())
            {
                Console.Write(enumerator.Current);
            }
            Console.WriteLine();
            Console.WriteLine("Value of the ulong variable in the BitArray64: {0}", bitArray.ToString());
        }
Exemplo n.º 9
0
        static void Main()
        {
            Console.WriteLine("----- Show foreach result -----");
            BitArray64 testBitArray = new BitArray64(8);
            foreach (var item in testBitArray)
            {
                Console.Write(item);
            }

            Console.WriteLine("\n----- Show Equals result -----");
            BitArray64 firstBitArray = new BitArray64(10);
            BitArray64 secondBitArray = new BitArray64(11);
            BitArray64 thirdBitArray = new BitArray64(10);
            Console.WriteLine("firstBitArray.Equals(secondBitArray): {0}",firstBitArray.Equals(secondBitArray));
            Console.WriteLine("firstBitArray.Equals(thirdBitArray): {0}", firstBitArray.Equals(thirdBitArray));
            Console.WriteLine("secondBitArray.Equals(thirdBitArray): {0}", secondBitArray.Equals(thirdBitArray));

            Console.WriteLine("\n----- Show hash code -----");
            Console.WriteLine("Hash code of firstBitArray is: {0}", firstBitArray.GetHashCode());
            Console.WriteLine("Hash code of secondBitArray is: {0}", secondBitArray.GetHashCode());

            Console.WriteLine("\n----- Show operator [] -----");
            for (int i = 0; i < testBitArray.Count(); i++)
            {
                Console.Write(testBitArray[i]);
            }

            Console.WriteLine("\n----- Show operators == and != -----");
            Console.WriteLine("firstBitArray == secondBitArray : {0}", firstBitArray == secondBitArray);
            Console.WriteLine("firstBitArray == thirdBitArray : {0}", firstBitArray == thirdBitArray);
            Console.WriteLine("firstBitArray != secondBitArray : {0}", firstBitArray != secondBitArray);
            Console.WriteLine("firstBitArray != thirdBitArray : {0}", firstBitArray != thirdBitArray);
        }
Exemplo n.º 10
0
    static void Main()
    {
        BitArray64 bits = new BitArray64();

        //set all bits at even index
        for (int i = 0; i < 64; i++)
        {
            if (i % 2 == 0)
            {
                bits[i] = 1;
            }
        }

        //clear all bits with index less than 10
        for (int i = 0; i < 10; i++)
        {
            bits[i] = 0;
        }

        IEnumerator<int> e = bits.GetEnumerator();
        e.MoveNext();
        Console.WriteLine();

        Console.WriteLine(bits);

        //foreach example
        foreach (var item in bits)
        {
            Console.WriteLine(item);
        }
    }
    public static void Main()
    {
        //Create an object of class BitArray64
        Console.WriteLine("Enter length");
        int length = int.Parse(Console.ReadLine());
        BitArray64 array = new BitArray64(length);

        //Assign its elements
        Console.WriteLine("Enter elements");
        for (int count = 0; count < length; count++)
        {
            array.AddElement(uint.Parse(Console.ReadLine()));
        }

        //Test ToString() method and indexer
        Console.WriteLine(array.ToString());
        Console.WriteLine("Enter index");
        int index = int.Parse(Console.ReadLine());
        Console.WriteLine(array[index]);

        //Use foreach to test the implementation of IEnumerable<int> interface
        foreach (var item in array)
        {
            Console.Write(item);
        }
    }
        static void Main()
        {
            Console.WriteLine("New BitArray64 bitArray1 (ulong as constuctor parameter):");
            BitArray64 bitArray1 = new BitArray64(25);
            Console.WriteLine(bitArray1);

            Console.WriteLine("New BitArray64 bitArray2 (string represented bynary number as constuctor parameter):");
            BitArray64 bitArray2 = new BitArray64("11001");
            Console.WriteLine(bitArray2);
            Console.WriteLine();

            Console.WriteLine("print foreach");

            foreach (var item in bitArray2)
            {
                Console.Write(item);
                Console.Write('\t');
            }

            Console.WriteLine();

            Console.WriteLine("Bit at position {0} = {1}", 3, bitArray2[3]);
            Console.WriteLine();

            Console.WriteLine("bitArray1 eaquals to bitArray2? {0}", bitArray1.Equals(bitArray2));
            Console.WriteLine("bitArray1 == bitArray2? {0}", bitArray1 == bitArray2);
            Console.WriteLine("bitArray1 != bitArray2? {0}", bitArray1 != bitArray2);
            Console.WriteLine();

               Console.WriteLine("Hash code: {0}", bitArray1.GetHashCode());
        }
        public static void Main()
        {
            BitArray64 bits = new BitArray64(123456789999);
            Console.WriteLine(string.Join("", bits));
            Console.WriteLine("Hash code: {0}", bits.GetHashCode());

            BitArray64 anotherBits = new BitArray64(123456789999);
            Console.WriteLine(string.Join("", anotherBits));
            Console.WriteLine("Hash code: {0}", anotherBits.GetHashCode());

            Console.WriteLine("Equals: {0}", bits.Equals(anotherBits));
            Console.WriteLine(" == {0}", bits == anotherBits);
            Console.WriteLine(" != {0}", bits != anotherBits);

            Console.WriteLine("Foreach:");
            foreach (var bit in bits)
            {
                Console.Write(bit);
            }

            Console.WriteLine();

            Console.WriteLine("For:");
            for (int i = 0; i < bits.Bits.Length; i++)
            {
                Console.Write(bits.Bits[i]);
            }

            Console.WriteLine();
        }
Exemplo n.º 14
0
    static void Main()
    {
        //Print some number in binary representation just to compare with it
        int num = 8765;

        Console.WriteLine(Convert.ToString(num, 2).PadLeft(64, '0'));
        //Making the BitArray64 with the same number but from ulong type
        ulong      number = 8765;
        BitArray64 bits   = new BitArray64(number);

        //Test foreach
        foreach (var bit in bits)
        {
            Console.Write(bit);
        }
        Console.WriteLine();
        Console.WriteLine("-----------------------------------------------------------------");
        //Making new BitArray64 and compare it with the old one
        BitArray64 bits2 = new BitArray64((ulong)8766);

        Console.WriteLine(bits.Equals(bits2));
        Console.WriteLine(bits == bits2);
        Console.WriteLine(bits != bits2);
        Console.WriteLine("-----------------------------------------------------------------");
        //Test ToString() method
        Console.WriteLine(bits);
        //Test overriten operator[]
        Console.WriteLine(bits[0]);
    }
Exemplo n.º 15
0
        public static void Main()
        {
            Console.Write("Enter a number: ");
            ulong number = ulong.Parse(Console.ReadLine());

            BitArray64 bitsOfNumber = new BitArray64(number);

            Console.WriteLine();

            Console.WriteLine(".ToString() method of the class BitArray64:\n{0}", bitsOfNumber);
            Console.WriteLine();

            Console.WriteLine("Bits of the number(got by foreach):");
            foreach (var bit in bitsOfNumber)
            {
                Console.Write("{0}", bit);
            }

            Console.WriteLine("\n");

            // The bits index started from 0 (right to the left on the previous lines)
            Console.WriteLine("Bit[3] = {0}", bitsOfNumber[3]);

            Console.WriteLine("\nHash code of the number {0} is {1}", bitsOfNumber.DecimalNumber, bitsOfNumber.GetHashCode());

            Console.WriteLine();
        }
Exemplo n.º 16
0
    static void Main()
    {
        Console.WriteLine("Testing the BitArray project.");
        Console.WriteLine("Creating a new instance of the BitArray64 class.");
        BitArray64 num = new BitArray64(415645645645456);

        Console.WriteLine("The number in base(10) is: {0}", num.Value);
        Console.WriteLine("The binary represenation of the number is: ");
        foreach (var bit in num.BitArray)
        {
            Console.Write(bit);
        }
        Console.WriteLine();

        Console.WriteLine("The hash code is: " + num.GetHashCode());
        Console.WriteLine("The bit value in position 63 is: {0}", num[63]);
        Console.WriteLine();

        Console.WriteLine("Creating a new instance of the BitArray64 class.");
        BitArray64 num2 = new BitArray64(ulong.MaxValue);

        Console.WriteLine("The number in base(10) is: {0}", num2.Value);
        Console.WriteLine("Number one == number two: {0}", num == num2);
        Console.WriteLine();

        Console.WriteLine("Test complete.");
    }
    static void Main()
    {
        BitArray64 bitArrayOne = new BitArray64(9999);
        Console.WriteLine("First number:");
        foreach (var bit in bitArrayOne)
        {
            Console.Write(bit);
        }
        Console.WriteLine();

        BitArray64 bitArrayTwo = new BitArray64(8888);
        Console.WriteLine("\nSecond number:");
        foreach (var bit in bitArrayTwo)
        {
            Console.Write(bit);
        }
        Console.WriteLine("\n");

        Console.WriteLine("---------------Test Equals() method-----------------");
        Console.WriteLine(bitArrayOne.Equals(bitArrayTwo));
        Console.WriteLine(bitArrayOne == bitArrayTwo);
        Console.WriteLine(bitArrayOne != bitArrayTwo);
        Console.WriteLine();

        Console.WriteLine("---------------Test ToString() method-----------------");
        Console.WriteLine(bitArrayOne);
        Console.WriteLine("\n---------------Test overriden operator []-----------------");
        Console.WriteLine(bitArrayOne[0]);
        Console.WriteLine(bitArrayTwo[0]);

        Console.WriteLine("\n---------------Test GetHashCode() method-----------------");
        Console.WriteLine(bitArrayOne.GetHashCode());
        Console.WriteLine(bitArrayTwo.GetHashCode());
        Console.WriteLine();
    }
Exemplo n.º 18
0
        public static void Main()
        {
            var testNumber = new BitArray64(254);

            // number as array of bits:
            Console.WriteLine(string.Join("", testNumber.BitArray));

            // check indexer
            Console.WriteLine(testNumber[60]);
            Console.WriteLine(testNumber[5]);

            // check enumerator
            foreach (var bit in testNumber)
            {
                Console.Write(bit);
            }
            Console.WriteLine();

            //check equals and ==
            var testNumber2 = new BitArray64(254);
            var testNumber3 = new BitArray64(122);

            Console.WriteLine(testNumber.Equals(testNumber2));
            Console.WriteLine(testNumber.Equals("11111110"));
            Console.WriteLine(testNumber.Equals(testNumber3));
            Console.WriteLine(testNumber == testNumber2);
            Console.WriteLine(testNumber != testNumber3);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            BitArray64 num = new BitArray64(2345678);
            //check the bits
            Console.WriteLine(string.Join("", num.ArrayBits));
            //check index
            Console.WriteLine(num[63]);
            Console.WriteLine(num[62]);
            Console.WriteLine(num[0]);
            //check enumeratora

            foreach (var bit in num)//тук само числото слагаме, за да видим дали сме му сложили foreacha
            {
                //оставила съм го да събира номера на 1 или 0 от аски таблица с 200, за да се види ясно!
                Console.WriteLine(bit);
            }

            //вграден форич за масив
               foreach (var bit in num.ArrayBits)
               {
               //tuk si izpisva 4isloto normalno
               Console.Write(bit);
               }
               Console.WriteLine();

            // check equals

               BitArray64 anothernum = new BitArray64(234567);
               Console.WriteLine(num.Equals(anothernum));

            //chech operators == and =!
               Console.WriteLine(num == anothernum);
               Console.WriteLine(num != anothernum);
        }
Exemplo n.º 20
0
    static void Main()
    {
        BitArray64 arr1 = new BitArray64(31);

        // Test Ienumerable<int> - must work with foreach
        int position = 0;
        foreach (var bit in arr1)
        {
            Console.WriteLine("Position {0}, Value -> {1}",position, bit);
            position++;
        }

        // Test set of a new bit value on specific position and Test ToString()
        Console.WriteLine(arr1);
        arr1[10] = 1;
        Console.WriteLine(arr1);

        arr1[10] = 0;
        Console.WriteLine(arr1);

        BitArray64 arr2 = new BitArray64(256);

        //Test == != equals
        Console.WriteLine(arr1==arr2); //false

        arr2.InputNumber = 31;
        Console.WriteLine(arr1 == arr2); //true

        // Test GetHashCode()
        Console.WriteLine(arr2.GetHashCode());
    }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.Title = "Test BitArray64";

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("Enter a number: ");
            ulong number = ulong.Parse(Console.ReadLine());

            BitArray64 bitsOfNumber = new BitArray64(number);

            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(".ToString() method of the class BitArray64:\n{0}", bitsOfNumber);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Bits of the number(got by foreach):");
            foreach (var bit in bitsOfNumber)
            {
                Console.Write("{0}", bit);
            }

            Console.WriteLine("\n");

            // The bits index started from 0 (right to the left on the previous lines)
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Bit[3] = {0}", bitsOfNumber[3]);

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\nHash code of the number {0} is {1}", bitsOfNumber.DecimalNumber, bitsOfNumber.GetHashCode());

            Console.WriteLine();
            Console.ResetColor();
        }
Exemplo n.º 22
0
    static void Main(string[] args)
    {
        BitArray64 bitArray = new BitArray64();

        for (int i = 0; i < 64; i++)
        {
            bitArray[i] = 0;
        }
        bitArray[2]  = 1;
        bitArray[36] = 1;

        Console.WriteLine("Showing the array...");
        Console.WriteLine("Using foreach:");
        foreach (var num in bitArray)
        {
            Console.Write(num);
        }
        Console.WriteLine();

        IEnumerator enumerator = bitArray.GetEnumerator();

        Console.WriteLine("Using enumerator:");
        while (enumerator.MoveNext())
        {
            Console.Write(enumerator.Current);
        }
        Console.WriteLine();
        Console.WriteLine("Value of the ulong variable in the BitArray64: {0}", bitArray.ToString());
    }
 static void Main()
 {
     ulong number1 = 205;
     ulong number2 = 206;
     ulong number3 = 205;
     BitArray64 test1 = new BitArray64(number1);
     BitArray64 test2 = new BitArray64(number2);
     BitArray64 test3 = new BitArray64(number3);
     Console.WriteLine("Equalty check:");
     Console.WriteLine(test1 != test2);
     Console.WriteLine(test1 == test3);
     Console.WriteLine("Hash codes check:");
     Console.WriteLine(test1.GetHashCode());
     Console.WriteLine(test2.GetHashCode());
     Console.WriteLine(test3.GetHashCode());
     int i = 0;
     Console.WriteLine("GetEnumerator() check:");
     foreach (var item in test1)
     {
         Console.Write(item);
         i++;
     }
     Console.WriteLine();
     Console.WriteLine("Indexer check:");
     for (i = 0; i < 64; i++)
     {
         Console.Write(test1[i]);
     }
     Console.WriteLine();
 }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            BitArray64 testOne = new BitArray64(16777225);
            BitArray64 testTwo = new BitArray64(1);
            BitArray64 testThree = new BitArray64(9);

            //Print all the number
            Console.WriteLine("testOne = {0}, testTwo = {1}, testThree = {2}\n", testOne, testTwo, testThree);

            //Comapre first two and second two
            Console.WriteLine("testOne == testTwo ? {0}", testOne == testTwo);

            Console.WriteLine("testTwo equals testThree ? {0}\n", testTwo.Equals(testThree));

            //Making the number  9 -> 1001
            testTwo[3] = 1;
            //Change, print and check again
            Console.WriteLine("testOne = {0}, testTwo = {1}, testThree = {2}", testOne, testTwo, testThree);
            Console.WriteLine("testTwo equals testThree ? {0}\n", testTwo.Equals(testThree));

            //Making the 24th bit 0, print and compare if NOT EQUAL
            testOne[24] = 0;
            Console.WriteLine("testOne = {0}, testTwo = {1}, testThree = {2}", testOne, testTwo, testThree);
            Console.WriteLine("testOne != (NOT EQUAL) testTwo ? {0}", testOne != testTwo);
        }
Exemplo n.º 25
0
    static void Main()
    {
        BitArray64 bits = new BitArray64();

        //set all bits at even index
        for (int i = 0; i < 64; i++)
        {
            if (i % 2 == 0)
            {
                bits[i] = 1;
            }
        }

        //clear all bits with index less than 10
        for (int i = 0; i < 10; i++)
        {
            bits[i] = 0;
        }

        IEnumerator <int> e = bits.GetEnumerator();

        e.MoveNext();
        Console.WriteLine();

        Console.WriteLine(bits);

        //foreach example
        foreach (var item in bits)
        {
            Console.WriteLine(item);
        }
    }
Exemplo n.º 26
0
    public static void Main()
    {
        // Initializing data types
        BitArray64 num1 = new BitArray64(212);
        BitArray64 num2 = new BitArray64(212);

        // Testing indexer
        int index = 7;
        Console.WriteLine("The bit at position {0} is:", index);
        Console.WriteLine(num1[index] + "\n");

        // Testing enumaration
        Console.WriteLine("Enumeration");
        foreach (var item in num1)
        {
            Console.Write(item);
        }

        Console.WriteLine();

        // Testing ToString()
        Console.WriteLine("\nToString()");
        Console.WriteLine(num1);

        // Testing comparing
        Console.WriteLine("num1 Equals num2 --> {0}", num1.Equals(num2));
        Console.WriteLine("num1 == num2 --> {0}", num1 == num2);
        Console.WriteLine("num1 != num2 --> {0}", num1 != num2);
    }
    static void Main()
    {
        int numInt = 123456789;
        Console.WriteLine(Convert.ToString(numInt, 2).PadLeft(64, '0'));

        ulong numUlong = 123456789;
        BitArray64 bits = new BitArray64(numUlong);

        foreach (var bit in bits)
        {
            Console.Write(bit);
        }
        Console.WriteLine();
        Console.WriteLine();

        BitArray64 bits2 = new BitArray64((ulong)8766);
        Console.WriteLine(bits.Equals(bits2));
        Console.WriteLine(bits == bits2);
        Console.WriteLine(bits != bits2);
        Console.WriteLine();

        Console.WriteLine(bits);

        Console.WriteLine(bits[0]);

        Console.WriteLine();
    }
Exemplo n.º 28
0
 static void Main()
 {
     BitArray64 num = new BitArray64(15234);
     //test with foreach
     foreach (var item in num)
     {
         Console.Write(item);
     }
     Console.WriteLine();
     //test indexer
     for (int i = 0; i < 64; i++)
     {
         Console.Write(num[63-i]);
     }
     Console.WriteLine();
     //compare to verify the rsult
     Console.WriteLine( Convert.ToString(15234, 2).PadLeft(64,'0'));
     //set any bit to zero or 1
     num[62] = 1;
     foreach (var item in num)
     {
         Console.Write(item);
     }
     Console.WriteLine();
 }
Exemplo n.º 29
0
        static void Main()
        {
            BitArray64 number1 = new BitArray64(5);
            BitArray64 number2 = new BitArray64(5);
            Console.WriteLine(String.Join("",number1.BitArray));

            //Test indexer
            Console.WriteLine(number1[0]);
            number1[3] = 1;

            //Test Equals
            Console.WriteLine(number1 == number2);

            //Test "=="
            Console.WriteLine(number1.Equals(number2));

            //Test enumerator
            foreach (var item in number1)
            {
                Console.Write(item);
            }

            //Test GetHashCode
            Console.WriteLine(number1.GetHashCode());
            Console.WriteLine(number1.GetHashCode());
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            BitArray64 arr = new BitArray64(5);

            arr.Add(18446744073709551615);
            arr.Add(204203);
            arr.Add(30494202);
            arr.Add(40494202);
            arr.Add(50494202);
            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }

            BitArray64 arr2 = new BitArray64(5);

            arr2.Add(20494202);
            arr2.Add(204203);
            arr2.Add(30494202);
            arr2.Add(40494202);
            arr2.Add(50494202);

            Console.WriteLine(arr.Equals(arr2));
            Console.WriteLine(arr.GetHashCode());

            arr2[0] = 1;
            Console.WriteLine("Check for equality: {0}", arr == arr2);
        }
        static void Main()
        {
            BitArray64 arrayOne= new BitArray64(3u);
            BitArray64 arrayTwo = new BitArray64(150u);

            Console.WriteLine("Binary number one:");
            Console.WriteLine(arrayOne);
            Console.WriteLine("Binary number two:");
            Console.WriteLine(arrayTwo);

            arrayOne[0] = 0;
            arrayTwo[0] = 1;

            Console.WriteLine("Binary number one changed:");
            Console.WriteLine(arrayOne);
            Console.WriteLine("Binary number two changed:");
            Console.WriteLine(arrayTwo);

            Console.WriteLine("\nNumber one == number two?");
            Console.WriteLine(arrayOne == arrayTwo);

            Console.WriteLine("\nNumber one is equal to itself?");
            Console.WriteLine(arrayOne.Equals(arrayOne));

            Console.WriteLine("\nNumber one !- number two?");
            Console.WriteLine(arrayOne != arrayTwo);

            Console.WriteLine("\nThe bit with index [2] of number one is:");
            Console.WriteLine(arrayOne[2]);

            Console.WriteLine("\nThe bit with index [2] of number two is:");
            Console.WriteLine(arrayTwo[2]);
        }
Exemplo n.º 32
0
        static void Main()
        {
            ulong uLongNumber1 = 888;
            BitArray64 number = new BitArray64(uLongNumber1);

            Console.WriteLine("Bits of the number {0}", uLongNumber1);
            foreach (var bit in number)
            {
                Console.Write(bit);
            }
            Console.WriteLine();
            Console.WriteLine("Bit at position 60 is {0}", number[60]);
            Console.WriteLine("Hash code of {0} is {1}", uLongNumber1, number.GetHashCode());

            ulong uLongNumber2 = 123456789;
            BitArray64 otherNumber = new BitArray64(uLongNumber2);
            Console.WriteLine("\nBits of the number {0}", uLongNumber2);
            foreach (var bit in otherNumber)
            {
                Console.Write(bit);
            }
            Console.WriteLine();

            Console.WriteLine("\n{0} == {1} ? {2}", uLongNumber1, uLongNumber2, number == otherNumber);
            Console.WriteLine("\n{0} != {1} ? {2}", uLongNumber1, uLongNumber2, number != otherNumber);
            Console.WriteLine("\n{0} equals {1} ? {2}\n", uLongNumber1, uLongNumber2, number.Equals(otherNumber));
        }
Exemplo n.º 33
0
        static void Main()
        {
            BitArray64 bitOne = new BitArray64(123456);

            BitArray64 bitTwo = new BitArray64(88888888888);

            BitArray64 bitMaxValue = new BitArray64(ulong.MaxValue);

            Console.WriteLine(bitOne); //test toString() and compare to foreach
            foreach (var bit in bitOne)//test foreach
            {
                Console.Write(bit);
            }

            Console.WriteLine();

            Console.WriteLine(bitTwo);
            Console.WriteLine(bitMaxValue); //test ulong max value

            Console.WriteLine(bitOne.Equals(bitTwo));

            Console.WriteLine(bitOne != bitTwo);

            Console.WriteLine(bitOne.GetHashCode());

            Console.WriteLine(bitTwo.GetHashCode());
        }
Exemplo n.º 34
0
 static void Main()
 {
     //Print some number in binary representation just to compare with it
     int num = 9578;
     Console.WriteLine(Convert.ToString(num, 2).PadLeft(64, '0'));
     //Making the BitArray64 with the same number but from ulong type
     ulong number = 9587;
     BitArray64 bits = new BitArray64(number);
     //Test foreach
     foreach (var bit in bits)
     {
         Console.Write(bit);
     }
     Console.WriteLine();
     Console.WriteLine("-----------------------------------------------------------------");
     //Making new BitArray64 and compare it with the old one
     BitArray64 bits2 = new BitArray64((ulong)8766);
     Console.WriteLine(bits.Equals(bits2));
     Console.WriteLine(bits == bits2);
     Console.WriteLine(bits != bits2);
     Console.WriteLine("-----------------------------------------------------------------");
     //Test ToString() method
     Console.WriteLine(bits);
     //Test overriten operator[]
     Console.WriteLine(bits[0]);
 }
        static void Main()
        {
            BitArray64 arr = new BitArray64(5);
            BitArray64 arr1 = new BitArray64(5);

            arr1[0] = 6;
            arr[0] = 4;

            Console.WriteLine("Use foreach.");
            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }

            Console.Write("\narr Equals arr1: ");
            Console.WriteLine(arr.Equals(arr1));

            Console.WriteLine("\nThe arr HashCode is {0}", arr.GetHashCode());

            Console.WriteLine("\narr == arr1: {0}", arr == arr1);

            Console.WriteLine("\narr != arr1: {0}", arr != arr1);

            Console.WriteLine("\narr: {0}", arr);
            Console.WriteLine("arr1: {0}", arr1);
        }
Exemplo n.º 36
0
 public static bool operator !=(BitArray64 bArr1, BitArray64 bArr2)
 {
     if (BitArray64.Equals(bArr1, bArr2))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 37
0
    public OptionalArray(int length)
    {
        _array = new T[length];
#if USE_BITARRAY64
        _hasValue = new BitArray();
#else
        _hasValue = new BitArray(length);
#endif
    }
Exemplo n.º 38
0
    public static void Main()
    {
        BitArray64 myTestBitArray = new BitArray64(1546878);

        foreach (var item in myTestBitArray)
        {
            Console.Write("{0}", item);
        }
    }
Exemplo n.º 39
0
    public override bool Equals(object obj)
    {
        BitArray64 otherBitArray = obj as BitArray64;

        if (obj == null)
        {
            return(false);
        }
        return(this.numberToConvert.Equals(otherBitArray.numberToConvert));
    }
Exemplo n.º 40
0
        public static void SetRandomBits(ref BitArray64 arr)
        {
            Random randomPosition = new Random();
            Random randomValue    = new Random();

            for (int i = 0; i < 64; i++)
            {
                arr[randomPosition.Next(0, 63)] = (uint)randomValue.Next(0, 1);
            }
        }
Exemplo n.º 41
0
 public static void Compare(BitArray64 arr1, BitArray64 arr2)
 {
     Console.WriteLine($"{arr1.Number} - {arr1}");
     Console.WriteLine($"{arr2.Number} - {arr2}");
     Console.WriteLine();
     Console.WriteLine($"{arr1.Number} equals to {arr2.Number}: {arr1.Equals(arr2)}");
     Console.WriteLine($"{arr1.Number} == {arr2.Number}: {arr1 == arr2}");
     Console.WriteLine($"{arr1.Number} != {arr2.Number}: {arr1 != arr2}");
     Console.WriteLine();
 }
Exemplo n.º 42
0
    public override bool Equals(object obj)
    {
        BitArray64 temp = obj as BitArray64;

        if (temp == null)
        {
            return(false);
        }
        return(this.Equals(temp));
    }
Exemplo n.º 43
0
        public void TestBitArrayIndexing()
        {
            // Arrange
            byte[]     byteArray = { 1, 2, 3, 4 };
            BitArray   reference = new BitArray(byteArray);
            BitArray64 dut       = new BitArray64(byteArray);

            // Assert
            Assert.Equals(reference.Count, dut.Count);
        }
Exemplo n.º 44
0
        private bool CompareElements(BitArray reference, BitArray64 dut)
        {
            bool res = true;

            for (int i = 0; i < reference.Count; i++)
            {
                res &= reference[i] == dut[i];
            }
            return(res);
        }
Exemplo n.º 45
0
        public void TestBitArray64Indexer1()
        {
            BitArray64 bitArray = new BitArray64();

            bitArray[23] = 1;
            bitArray[24] = 1;
            bitArray[25] = 1;
            bitArray[49] = 1;

            Assert.AreEqual(562950012141568U, bitArray.BitsValue);
        }
Exemplo n.º 46
0
 //equals
 public bool Equals(BitArray64 value)
 {
     if (ReferenceEquals(null, value))
     {
         return(false);
     }
     if (ReferenceEquals(this, value))
     {
         return(true);
     }
     return(this.Number == value.Number);
 }
Exemplo n.º 47
0
        public void TestBitArray64Indexer2()
        {
            BitArray64 bitArray = new BitArray64();

            bitArray[19] = 1;
            bitArray[49] = 1;
            bitArray[62] = 1;
            bitArray[63] = 1;

            Assert.AreEqual(
                "1100000000000010000000000000000000000000000010000000000000000000", bitArray.ToString());
        }
Exemplo n.º 48
0
        public BitArray64 CreateComponentBits(int entityId)
        {
            var bits = new BitArray64();

            for (int componentId = 0; componentId < _componentMappers.Count(); componentId++)
            {
                var mapper = _componentMappers[componentId];

                bits[componentId] = mapper?.Has(entityId) ?? false;
            }

            return(bits);
        }
Exemplo n.º 49
0
    public override bool Equals(object obj)
    {
        // If the cast is invalid, the result will be null
        BitArray64 other = obj as BitArray64;

        // Check if we have valid not null BitArray64 object
        if (other == null)
        {
            return(false);
        }

        return(this.bitsValue == other.bitsValue);
    }
Exemplo n.º 50
0
    // Overrides
    public override bool Equals(object obj)
    {
        BitArray64 arr = obj as BitArray64;

        if (arr == null)
        {
            return(false);
        }
        if (this.Value != arr.Value)
        {
            return(false);
        }
        return(true);
    }
Exemplo n.º 51
0
    public override bool Equals(object obj)
    {
        BitArray64 arr = obj as BitArray64;

        for (int i = 0; i < 64; i++)
        {
            ulong p = (ulong)1 << i;
            if (((this.number & p) >> i) != ((arr.number & p) >> i))
            {
                return(false);
            }
        }
        return(true);
    }
Exemplo n.º 52
0
        public static string ToString(BitArray64 value)
        {
            return(string.Create(/*"BitArray64{".Length*/ 12 + /*64 bits*/ 64 + /*"}".Length"*/ 1, value, (dst, v) => {
                ReadOnlySpan <char> prefix = "BitArray64{";
                prefix.CopyTo(dst);
                dst[^ 1] = '}';

                var locdata = unchecked ((Int64)v._Data);
                dst = dst.Slice(prefix.Length, 64);
                for (int i = 0; i < dst.Length; i++)
                {
                    dst[i] = (0 > locdata) ? '1' : '0';
                    locdata <<= 1;
                }
            }));
Exemplo n.º 53
0
    static void Main(string[] args)
    {
        Console.Write("Please enter an integer number: ");
        ulong input = ulong.Parse(Console.ReadLine());

        BitArray64 bits = new BitArray64(input);

        Console.WriteLine("64bit representation of the number {0}", input);

        foreach (var item in bits)
        {
            Console.Write(item);
        }
        Console.WriteLine();
    }
Exemplo n.º 54
0
        static void Main()
        {
            #region tasks[1-3]
            Student firstStudent = new Student("Pesho", "Petrov", "Ivanov", "20012", "08888888", "pesho@abv,bg", "OOP",
                                               Speciality.ComputerSystem, University.BurgasFreeUniversity, Faculty.CS);

            Student secondStudent = new Student("Toshko", "Todorov", "Yordanov", "20013", "08881674", "*****@*****.**", "C#",
                                                Speciality.ComputerTechnology, University.SofiaUniversity, Faculty.EE);

            Student thirdStudent = new Student("Kalistrati", "Carvulanov", "Popishki", "20013", "09123848", "*****@*****.**", "suspended",
                                               Speciality.Medicine, University.UniversityOfEconomics, Faculty.FMI);

            Console.WriteLine(firstStudent);
            Console.WriteLine(new string('-', 30));

            Console.WriteLine(firstStudent.Equals(secondStudent));
            Console.WriteLine(firstStudent.Equals(firstStudent));
            Console.WriteLine(new string('-', 30));

            Console.WriteLine(firstStudent.GetHashCode());
            Console.WriteLine(new string('-', 30));

            Student newStudent = firstStudent.Clone() as Student;
            Console.WriteLine(newStudent);
            Console.WriteLine(new string('-', 30));

            Console.WriteLine(newStudent.CompareTo(secondStudent));
            Console.WriteLine(new string('-', 30));
            #endregion

            #region task4
            Person testPerson = new Person("BaiIvan", 82);
            Console.WriteLine(testPerson);
            Person testPersonWithoutAge = new Person("BaiPenio");
            Console.WriteLine(testPersonWithoutAge);

            #endregion

            #region task5-6
            BitArray64 number = new BitArray64(18);
            foreach (var digit in number)
            {
                Console.Write(digit);
            }
            Console.WriteLine();
            Console.WriteLine(number.GetHashCode());
            #endregion
        }
Exemplo n.º 55
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }

        BitArray64 arr = obj as BitArray64;

        if ((object)arr == null)
        {
            return(false);
        }

        return(this.bits == arr.bits);
    }
    static void Main()
    {
        var bits = new BitArray64(1234);

        Console.WriteLine(bits.DecimalValue);

        foreach (var item in bits)
        {
            Console.Write(item);
        }

        var bits2 = new BitArray64(1024 * 1024 * 1024);

        Console.WriteLine(bits2);
        Console.WriteLine(bits2.DecimalValue);
    }
Exemplo n.º 57
0
    //implement Equals(...),GetHashCode(),[],==,!=
    public override bool Equals(object param)
    {
        BitArray64 bitArray = param as BitArray64;

        if ((object)bitArray == null)
        {
            return(false);
        }

        if (!Object.Equals(this.number, bitArray.number))
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 58
0
    static void Main()
    {
        BitArray64 myNumber    = new BitArray64(7625671467);
        BitArray64 otherNumber = new BitArray64(178657854);

        Console.WriteLine(myNumber != otherNumber);
        Console.WriteLine(myNumber == otherNumber);
        Console.WriteLine(myNumber.ToString());
        Console.WriteLine(otherNumber.ToString());
        Console.WriteLine(myNumber.GetHashCode());
        Console.WriteLine(otherNumber.GetHashCode());

        Console.WriteLine(myNumber[0]);
        myNumber[0] = 0;
        Console.WriteLine(myNumber.ToString());
    }
Exemplo n.º 59
0
    static void Main()
    {
        BitArray64 a = new BitArray64(8);
        BitArray64 b = new BitArray64(8);

        Console.WriteLine(String.Join("", a.BitArray));
        Console.WriteLine(b[0]);
        b[3] = 1;
        Console.WriteLine(a == b);
        Console.WriteLine(a.Equals(b));
        foreach (var item in a)
        {
            Console.Write(item);
        }
        Console.WriteLine();
    }
Exemplo n.º 60
0
        private static void TestArr()
        {
            var arr = new BitArray64();

            arr[8] = 1;
            Console.WriteLine(arr);

            arr = new BitArray64(1646235);
            Console.WriteLine(arr);

            var arr2 = new BitArray64(100);

            arr = new BitArray64(100);
            Console.WriteLine(arr == arr2);
            Console.WriteLine(arr.GetHashCode());
            Console.WriteLine(arr2.GetHashCode());
        }