Example #1
0
        public int ReadInt32(int numberOfBits)
        {
            int newPosition = bitPosition + numberOfBits;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }

            uint value = BitWriter.ReadUInt32(data, numberOfBits, bitPosition);

            bitPosition += numberOfBits;

            if (numberOfBits == 32)
            {
                return((int)value);
            }

            int signBit = 1 << (numberOfBits - 1);

            if ((value & signBit) == 0)
            {
                return((int)value);                // positive
            }
            // negative
            unchecked
            {
                uint mask = ((uint)-1) >> (33 - numberOfBits);
                uint tmp  = (value & mask) + 1;
                return(-((int)tmp));
            }
        }
Example #2
0
        public UInt32 ReadUInt32(int numberOfBits)
        {
            int newPosition = bitPosition + numberOfBits;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }
            uint value = BitWriter.ReadUInt32(data, numberOfBits, bitPosition);

            bitPosition += numberOfBits;
            return(value);
        }
Example #3
0
        public uint ReadUInt32()
        {
            int newPosition = bitPosition + 32;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }
            uint value = BitWriter.ReadUInt32(data, 32, bitPosition);

            bitPosition += 32;
            return(value);
        }
Example #4
0
        //public byte ReadInt16( int numberOfBits )

        public ushort ReadUInt16()
        {
            int newPosition = bitPosition + 16;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }
            uint value = BitWriter.ReadUInt32(data, 16, bitPosition);

            bitPosition = newPosition;
            return((ushort)value);
        }
Example #5
0
        public ulong ReadUInt64()
        {
            int newPosition = bitPosition + 64;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }
            ulong low = BitWriter.ReadUInt32(data, 32, bitPosition);

            bitPosition += 32;
            ulong high = BitWriter.ReadUInt32(data, 32, bitPosition);

            bitPosition += 32;
            ulong value = low + (high << 32);

            return(value);
        }
Example #6
0
        public ulong ReadUInt64(int numberOfBits)
        {
            int newPosition = bitPosition + numberOfBits;

            if (overflow || newPosition > endBitPosition)
            {
                overflow = true;
                return(0);
            }

            ulong value;

            if (numberOfBits <= 32)
            {
                value = (ulong)BitWriter.ReadUInt32(data, numberOfBits, bitPosition);
            }
            else
            {
                value  = BitWriter.ReadUInt32(data, 32, bitPosition);
                value |= BitWriter.ReadUInt32(data, numberOfBits - 32, bitPosition) << 32;
            }
            bitPosition += numberOfBits;
            return(value);
        }