Exemplo n.º 1
0
        /// <summary>
        /// Reads a 64 bit integer value written using WriteRangedInteger() (64 version)
        /// </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>
        public long ReadRangedInteger(long min, long max)
        {
            ulong range   = (ulong)(max - min);
            int   numBits = NetUtility.BitsToHoldUInt64(range);

            ulong rvalue = ReadUInt64(numBits);

            return(min + (long)rvalue);
        }
        /// <summary>
        /// Writes an integer with the least amount of bits need for the specified range
        /// Returns number of bits written
        /// </summary>
        public int WriteRangedInteger(long min, long max, long value)
        {
            NetException.Assert(value >= min && value <= max, "Value not within min/max range!");

            ulong range   = (ulong)(max - min);
            int   numBits = NetUtility.BitsToHoldUInt64(range);

            ulong rvalue = (ulong)(value - min);

            Write(rvalue, numBits);

            return(numBits);
        }