ToInt32() public static method

Returns a 32-bit signed integer converted from two bytes at a specified position in a byte array.
public static ToInt32 ( byte array, int index ) : int
array byte Specify an array of bytes.
index int Specify the starting position.
return int
Ejemplo n.º 1
0
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            if (lengthOfItems != 4)
            {
                throw new StreamObjectParseErrorException(currentIndex, "Win32Error", "Stream object over-parse error", null);
            }

            this.ErrorCode = LittleEndianBitConverter.ToInt32(byteArray, currentIndex);

            currentIndex += 4;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            if (lengthOfItems != 4)
            {
                throw new StreamObjectParseErrorException(currentIndex, "ProtocolError", "Stream object over-parse error", null);
            }

            this.ErrorCode = (ProtocolErrorCode)LittleEndianBitConverter.ToInt32(byteArray, currentIndex);

            if (!Enum.IsDefined(typeof(ProtocolErrorCode), this.ErrorCode))
            {
                throw new StreamObjectParseErrorException(currentIndex, "ProtocolError", "Unexpected error code value " + this.ErrorCode, null);
            }

            currentIndex += 4;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Read specified bit length content as an Int32 type and increase the bit offset with the specified length.
 /// </summary>
 /// <param name="readingLength">Specify the reading bit length.</param>
 /// <returns>Return the Int32 type value.</returns>
 public int ReadInt32(int readingLength)
 {
     byte[] uint32Bytes = this.GetBytes(readingLength, 4);
     return(LittleEndianBitConverter.ToInt32(uint32Bytes, 0));
 }