Example #1
0
        /// <summary>
        /// Reads a 32-bit <see cref="int"/> written by <see cref="WriteRanged"/>.
        /// </summary>
        /// <param name="min">The minimum value used when writing the value</param>
        /// <param name="max">The maximum value used when writing the value</param>
        /// <returns>A signed integer value larger or equal to MIN and smaller or equal to MAX</returns>
        /// <exception cref="EndOfMessageException"></exception>
        public static int ReadRangedInt32(this IBitBuffer buffer, int min, int max)
        {
            uint range   = (uint)(max - min);
            int  numBits = NetBitWriter.BitsForValue(range);
            uint rvalue  = buffer.ReadUInt32(numBits);

            return((int)(min + rvalue));
        }