Microsoft.Protocols.TestSuites.SharedAdapter.LittleEndianBitConverter.ToInt16 C# (CSharp) Method

ToInt16() public static method

Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
public static ToInt16 ( byte array, int index ) : short
array byte Specify an array of bytes.
index int Specify the starting position.
return short
        public static short ToInt16(byte[] array, int index)
        {
            CheckByteArgument(array, index, 4);
            return unchecked((short)ConvertFromBytes(array, index, 2));
        }

Usage Example

Example #1
0
 /// <summary>
 /// Read specified bit length content as an UInt16 type and increase the bit offset with the specified length.
 /// </summary>
 /// <param name="readingLength">Specify the reading bit length.</param>
 /// <returns>Return the UInt16 value.</returns>
 public short ReadInt16(int readingLength)
 {
     byte[] uint16Bytes = this.GetBytes(readingLength, 2);
     return(LittleEndianBitConverter.ToInt16(uint16Bytes, 0));
 }