Ejemplo n.º 1
0
        /// <summary>
        /// Returns a 24-bit signed integer converted from three bytes, accounting for target endian-order, at a specified position in a byte array.
        /// </summary>
        /// <param name="value">An array of bytes (i.e., buffer containing binary image of value).</param>
        /// <param name="startIndex">The starting position within value.</param>
        /// <returns>A 24-bit signed integer formed by three bytes beginning at startIndex.</returns>
        /// <exception cref="ArgumentNullException">value is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
        public Int24 ToInt24(byte[] value, int startIndex)
        {
            byte[] buffer = new byte[3];

            m_copyBuffer(value, startIndex, buffer, 0, 3);

            return(Int24.GetValue(buffer, 0));
        }
Ejemplo n.º 2
0
 /// <summary>Performs proper bitwise conversion between unsigned and signed value</summary>
 /// <remarks>
 /// <para>This function is useful because CType(n, Int24) will throw an OverflowException for values greater than Int24.MaxValue.</para>
 /// <para>For example, this function correctly converts unsigned 24-bit integer 16777215 (i.e., UInt24.MaxValue) to signed 24-bit integer -1.</para>
 /// </remarks>
 /// <param name="unsignedInt">Unsigned UInt24 that is passed in to be converted to a signed Int24.</param>
 /// <returns>The Int24 value.</returns>
 public static Int24 ToInt24(UInt24 unsignedInt)
 {
     return(Int24.GetValue(UInt24.GetBytes(unsignedInt), 0));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads three bytes from the binary reader and returns an <see cref="Int24"/>
        /// </summary>
        /// <param name="reader">Binary reader</param>
        /// <returns><see cref="Int24"/></returns>
        public static Int24 ReadInt24(this BinaryReader reader)
        {
            var bytes = reader.ReadBytes(3);

            return(Int24.GetValue(bytes, 0));
        }