//		public static bool reverseSort = false;
        public int CompareTo(object obj)
        {
            SimpleBitArray i = (SimpleBitArray)obj;

//			for (int loop = 0; loop < bitArray.Length; loop++)

/*
 *                      if (reverseSort)
 *                      {
 *                              for (int loop = 0; loop < bitArray.Length * BITS_IN_ULONG; loop++)
 *                              {
 *                                      if ((!Get(loop)) && i.Get(loop))
 *                                              return 1;
 *                                      if (Get(loop) && (!i.Get(loop)))
 *                                              return -1;
 *                              }
 *                      }
 *                      else
 */         {
                for (int loop = bitArray.Length - 1; loop >= 0; loop--)
                {
                    if (bitArray[loop] > i.bitArray[loop])
                    {
                        return(1);
                    }
                    if (bitArray[loop] < i.bitArray[loop])
                    {
                        return(-1);
                    }
                }
            }

            return(0);
        }
 public SimpleBitArray(SimpleBitArray copy)
 {
     bitArray = (ulong[])copy.bitArray.Clone();
     maxValue = copy.maxValue;
     minValue = copy.minValue;
     size     = copy.size;
     itemSum  = copy.itemSum;
 }
        public SimpleBitArray Xor(SimpleBitArray other)
        {
            SimpleBitArray res = new SimpleBitArray(size);

            for (int loop = 0; loop < bitArray.Length; loop++)
            {
                res.bitArray[loop] = bitArray[loop] ^ other.bitArray[loop];
            }

            return(res);
        }
        public bool IsContaining(SimpleBitArray other)
        {
            for (int loop = 0; loop < bitArray.Length; loop++)
            {
                if ((bitArray[loop] & other.bitArray[loop]) != other.bitArray[loop])
                {
                    return(false);
                }
            }

            return(true);
        }
        public SimpleBitArray And(SimpleBitArray other)
        {
            SimpleBitArray res = new SimpleBitArray(size);

            res.minValue = Math.Max(minValue, other.minValue);
            res.maxValue = Math.Min(maxValue, other.maxValue);

            for (int loop = 0; loop < bitArray.Length; loop++)
            {
                res.bitArray[loop] = bitArray[loop] & other.bitArray[loop];
            }

            return(res);
        }
        public bool IsOneItemDiff(SimpleBitArray other)
        {
            bool foundOneBit = false;

            for (int loop = 0; loop < bitArray.Length; loop++)
            {
                ulong diff = bitArray[loop] ^ other.bitArray[loop];
                if (diff == 0)
                {
                    continue;
                }

                if (foundOneBit == true)
                {
                    return(false);
                }

                // Find the first '1' in the number
                while ((diff & 0x01) == 0x00)                 // <==> (n & 0x01) != 0x01
                {
                    diff = diff >> 1;
                }

                // The first bit is '1' (n & 0x01 == 0x01), if it's the only bit than
                // n == 1
                // Another option is to check with XOR : (n ^ 0x01) == 0
                if (diff == 1)
                {
                    foundOneBit = true;
                }
                else
                {
                    return(false);                    // More then one bit on in this ulong
                }
            }

            return(true);
        }