Exemple #1
0
        public BitVector ReadBitVector(int length)
        {
            byte value = 0;
            byte mask = 0;

            BitVector bits = new BitVector(length);
            for(int i = 0; i < length; i++)
            {
                if(mask == 0)
                {
                    value = ReadByte();
                    mask = 0x80;
                }

                if((value & mask) != 0)
                    bits.SetBit(i);

                mask >>= 1;
            }

            // TODO: Make this a warning, not an exception.
            //while(mask != 0)
            //{
            //    if((value & mask) != 0)
            //        throw new InvalidDataException();
            //
            //    mask >>= 1;
            //}

            return bits;
        }
Exemple #2
0
        public BitVector ReadBitVector2(int length)
        {
            byte allSet = ReadByte();
            if(allSet == 0)
                return ReadBitVector(length);

            var bits = new BitVector(length);
            for(int i = 0; i < length; i++)
                bits.SetBit(i);
            return bits;
        }
Exemple #3
0
        private BitVector ReadBitVector(int length)
        {
            var bits = new BitVector(length);

            byte data = 0;
            byte mask = 0;

            for (int i = 0; i < length; i++)
            {
                if (mask == 0)
                {
                    data = ReadByte();
                    mask = 0x80;
                }

                if ((data & mask) != 0)
                    bits.SetBit(i);

                mask >>= 1;
            }

            return bits;
        }