C# BitConverter GetBytes(UInt16)

Description

BitConverter GetBytes(UInt16) returns the specified 16-bit unsigned integer value as an array of bytes.

Syntax

BitConverter.GetBytes(UInt16) has the following syntax.


[CLSCompliantAttribute(false)]
public static byte[] GetBytes(
  ushort value
)

Parameters

BitConverter.GetBytes(UInt16) has the following parameters.

  • value - The number to convert.

Returns

BitConverter.GetBytes(UInt16) method returns

Example

The following code example converts the bit patterns of UInt16 values to Byte arrays with the GetBytes method.


using System;/*from w w  w.jav  a2s  . c om*/

class GetBytesUInt64Demo
{

    public static void Main( )
    {
        byte[ ] byteArray = BitConverter.GetBytes( (UInt16)1000 );
        Console.WriteLine(BitConverter.ToString( byteArray ) );

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version