Esempio n. 1
0
        public long this[BitVector64.Section section]
        {
            get
            {
                return ((data >> section.Offset) & section.Mask);
            }

            set
            {
                if (value < 0)
                    throw new ArgumentException("Section can't hold negative values");
                if (value > section.Mask)
                    throw new ArgumentException("Value too large to fit in section");
                this.data &= ~(section.Mask << section.Offset);
                this.data |= (value << section.Offset);
            }
        }
Esempio n. 2
0
        public static string ToString(BitVector64 value)
        {
            StringBuilder sb = new StringBuilder(0x2d);
            sb.Append("BitVector64{");
            ulong data = (ulong)value.Data;
            for (int i = 0; i < 0x40; i++)
            {
                sb.Append(((data & 0x8000000000000000) == 0) ? '0' : '1');
                data = data << 1;
            }

            sb.Append("}");
            return sb.ToString();

            //StringBuilder b = new StringBuilder();
            //b.Append("BitVector64{");
            //ulong mask = (ulong)Convert.ToInt64(0x8000000000000000);
            //while (mask > 0)
            //{
            //    b.Append((((ulong)value.Data & mask) == 0) ? '0' : '1');
            //    mask >>= 1;
            //}
            //b.Append('}');
            //return b.ToString();
        }
Esempio n. 3
0
 public BitVector64(BitVector64 source)
 {
     this.data = source.data;
 }
Esempio n. 4
0
        public static Section CreateSection(int maxValue, BitVector64.Section previous)
        {
            if (maxValue < 1)
                throw new ArgumentException("maxValue");

            int bit = HighestSetBit(maxValue) + 1;
            int mask = (1 << bit) - 1;
            int offset = previous.Offset + NumberOfSetBits(previous.Mask);

            if (offset > 64)
            {
                throw new ArgumentException("Sections cannot exceed 64 bits in total");
            }

            return new Section((short)mask, (short)offset);
        }