Exemplo n.º 1
0
        static void Main()
        {
            BitArray64 bitArray = new BitArray64(3216549);

            Console.WriteLine(bitArray.Value);

            Console.WriteLine(bitArray.GetHashCode());

            BitArray64 secondBitArray = new BitArray64();

            if (bitArray == secondBitArray)
            {
                Console.WriteLine("The two are equal.");
            }
            else
            {
                Console.WriteLine("The two are not equal.");
            }

            for (int i = 0; i < 64; i++)
            {
                secondBitArray[i] = (byte)randomGen.Next(0, 2);
            }

            Console.WriteLine(secondBitArray);

            Console.WriteLine(secondBitArray.Value);

            Console.WriteLine(secondBitArray.GetHashCode());

            foreach (int bit in secondBitArray)
            {
                Console.WriteLine(bit);
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 private static void RandomFillBitArray64(BitArray64 bitArray, Random rand)
 {
     for (int i = 0; i < 64; i++)
     {
         bitArray[i] = (byte)(rand.Next() % 2);
     }
 }
Exemplo n.º 4
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.º 5
0
        public static void Main(string[] args)
        {
            var num = new BitArray64();

            num[0]  = 1;
            num[4]  = 0;
            num[22] = 1;
            Console.WriteLine(num.ToString());
        }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            if (obj as BitArray64 == null)
            {
                return(false);
            }
            BitArray64 arr2 = obj as BitArray64;

            return(this.Number == arr2.Number);
        }
Exemplo n.º 7
0
        public override bool Equals(object obj)
        {
            BitArray64 otherArray = obj as BitArray64;

            if (otherArray == null)
            {
                return(false);
            }

            return(this.Value == otherArray.Value);
        }
Exemplo n.º 8
0
        //Define a class BitArray64 to hold 64 bit values inside an ulong value. Implement IEnumerable<int> and Equals(…), GetHashCode(), [], == and !=.

        static void Main()
        {
            BitArray64 p = new BitArray64(7);

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

            Console.WriteLine("----------");
            Console.WriteLine(p[63]);
        }
Exemplo n.º 9
0
        public override bool Equals(object obj)
        {
            BitArray64 lala = (BitArray64)obj;

            for (int i = 0; i < this.Length; i++)
            {
                if (this[i] != lala[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 10
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.º 11
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            BitArray64 bitArray64 = obj as BitArray64;

            if (bitArray64 == null)
            {
                return(false);
            }

            return(this.Bits == bitArray64.Bits);
        }
Exemplo n.º 12
0
        public override bool Equals(object obj)
        {
            if (!(obj is BitArray64))
            {
                return(false);
            }
            BitArray64 other = obj as BitArray64;

            if (ReferenceEquals(other, null))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            return(this.Number == other.Number);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            BitArray64 number      = new BitArray64(222l);
            BitArray64 otherNumber = new BitArray64(2220l);

            Console.WriteLine("Bits of the number {0}", number.Number);
            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}", number.Number, number.GetHashCode());

            Console.WriteLine("number == otherNumber -> {0}", number == otherNumber);
            Console.WriteLine("number != otherNumber -> {0}", number != otherNumber);
            Console.WriteLine("number equals otherNumber -> {0}", number.Equals(otherNumber));
        }
Exemplo n.º 14
0
        public static void Main()
        {
            BitArray64 test  = new BitArray64(4534543);
            BitArray64 test1 = new BitArray64(54545454545);

            Console.WriteLine(test);

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

            Console.WriteLine(test.Equals(test1));
            Console.WriteLine(test != test1);
            Console.WriteLine(test.GetHashCode());
            Console.WriteLine(test1.GetHashCode());
        }
Exemplo n.º 15
0
        //Equals() overriden
        public override bool Equals(object obj)
        {
            if (!(obj is BitArray64))
            {
                //also, if obj is null, false will be returned
                return(false);
            }

            BitArray64 num = obj as BitArray64;

            //using the static method ensures no nullref exception will be thrown
            if (!Object.Equals(this.Value, num.Value))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 16
0
        public static void Main()
        {
            Random rand = new Random();

            BitArray64[] arrayOfBitArray64 = new BitArray64[] { new BitArray64(), new BitArray64(), new BitArray64(), new BitArray64(ulong.MaxValue) };

            RandomFillBitArray64(arrayOfBitArray64[0], rand);
            RandomFillBitArray64(arrayOfBitArray64[1], rand);
            arrayOfBitArray64[2] = arrayOfBitArray64[0];

            for (int i = 0; i < arrayOfBitArray64.Length; i++)
            {
                Console.WriteLine("BitArray64[{0}] = {1}", i, arrayOfBitArray64[i]);
            }

            Console.WriteLine();
            Console.WriteLine("Test operators:");
            Console.WriteLine("BitArray64[0] == BitArray64[1]: {0}", arrayOfBitArray64[0] == arrayOfBitArray64[1]);
            Console.WriteLine("BitArray64[0] != BitArray64[1]: {0}", arrayOfBitArray64[0] != arrayOfBitArray64[1]);
            Console.WriteLine("BitArray64[0] == BitArray64[2]: {0}", arrayOfBitArray64[0] == arrayOfBitArray64[2]);
            Console.WriteLine("BitArray64[0] != BitArray64[2]: {0}", arrayOfBitArray64[0] != arrayOfBitArray64[2]);
        }
Exemplo n.º 17
0
 public static bool operator !=(BitArray64 array1, BitArray64 array2)
 {
     return(!(BitArray64.Equals(array1, array2)));
 }
Exemplo n.º 18
0
 public static bool operator !=(BitArray64 val1, BitArray64 val2)
 {
     return(!BitArray64.Equals(val1, val2));
 }
Exemplo n.º 19
0
 public static bool operator ==(BitArray64 bitArray1, BitArray64 bitArray2)
 {
     return(BitArray64.Equals(bitArray1, bitArray2));
 }
Exemplo n.º 20
0
 public static bool operator !=(BitArray64 bitArray64A, BitArray64 bitArray64B)
 {
     return(!BitArray64.Equals(bitArray64A, bitArray64B));
 }
Exemplo n.º 21
0
 public static bool operator !=(BitArray64 first, BitArray64 second)
 {
     return(!BitArray64.Equals(first, second));
 }