Пример #1
0
        public static BitVector operator +(BitVector a, BitVector b)
        {

            var result = new Bit[a._count];

            Bit carry = Bit.False;

            for (int i = 0; i < a._count; i++)
            {
                result[i] = a[i] ^ b[i] ^ carry;
                carry = (a[i] & b[i]) | (a[i] & carry) | (b[i] & carry);
            }

            return new BitVector(result);
        }
Пример #2
0
 public BitVector Resize(int size)
 {
     Bit[] result = new Bit[size];
     for (int i = 0; i < size; i++)
     {
         if (i < _count)
             result[i] = _bits[i];
         else
         {
             result[i] = Bit.False;
         }
     }
     return new BitVector(result);
 }
Пример #3
0
        public static BitVector operator >>(BitVector value, int shift)
        {
            var result = new Bit[value._count];

            for (int i = 0; i < value._count; i++)
            {
                result[i] = Bit.False;
            }
            for (int i = 0; i < value._count; i++)
            {
                if (i - shift >=0)
                    result[(i - shift)] = value._bits[i];
            }
            return new BitVector(result);
        }
Пример #4
0
 public BitVector(Bit[] bits)
 {
     _bits = (Bit[]) bits.Clone();
     _count = _bits.Length;            
 }
Пример #5
0
        public BitVector RotateLeft(int shift)
        {
            shift = shift%_count;

            var result = new Bit[_count];

            for (int i = 0; i < _count; i++)
            {
                result[(i + shift) % _count] = _bits[i];
            }
            return new BitVector(result);
        }
Пример #6
0
        private static BitVector Convert(uint u, int count)
        {
            var r = new Bit[count];
            for (int i = 0; i < count; i++)
            {
                r[i] = Bit.False;
            }
            int j = 0;
            while (u != 0)
            {
                if (u % 2 == 1)
                    r[j] = Bit.True;

                u = u/2;
                j++;
            }
            return new BitVector(r);
        }
Пример #7
0
 public bool Equals(Bit other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._expression, _expression);
 }