C# BitConverter ToInt16
Description
BitConverter ToInt16
returns a 16-bit signed integer
converted from two bytes at a specified position in a byte array.
Syntax
BitConverter.ToInt16
has the following syntax.
public static short ToInt16(
byte[] value,
int startIndex
)
Parameters
BitConverter.ToInt16
has the following parameters.
value
- An array of bytes.startIndex
- The starting position within value.
Returns
BitConverter.ToInt16
method returns A 16-bit signed integer formed by two bytes beginning at startIndex.
Example
The following code example converts elements of Byte arrays to Int16 values with the ToInt16 method.
using System;//www . j ava 2s . c o m
class BytesToInt16Demo
{
public static void Main( )
{
byte[ ] byteArray =
{ 15, 0, 0, 128, 16, 39, 240, 216, 241, 255, 127 };
short value = BitConverter.ToInt16( byteArray, 1);
Console.WriteLine(value );
}
}
The code above generates the following result.