C# BitConverter ToUInt16
Description
BitConverter ToUInt16
returns a 16-bit unsigned integer
converted from two bytes at a specified position in a byte array.
Syntax
BitConverter.ToUInt16
has the following syntax.
[CLSCompliantAttribute(false)]/*from w w w .ja v a 2 s . co m*/
public static ushort ToUInt16(
byte[] value,
int startIndex
)
Parameters
BitConverter.ToUInt16
has the following parameters.
value
- The array of bytes.startIndex
- The starting position within value.
Returns
BitConverter.ToUInt16
method returns A 16-bit unsigned integer formed by two bytes beginning at startIndex.
Example
The following code example converts elements of Byte arrays to UInt16 values with the ToUInt16 method.
using System;//w w w . j a v a2s . c om
class BytesToUInt16Demo
{
public static void Main( )
{
byte[] bytes = {15, 0, 0, 255, 3, 16, 39, 255, 255, 127 };
ushort value = BitConverter.ToUInt16( bytes, 2 );
Console.WriteLine(value );
}
}
The code above generates the following result.