This documentation is archived and is not being maintained.

BitConverter.GetBytes Method (Int16)

Returns the specified 16-bit signed integer value as an array of bytes.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Shared Function GetBytes ( _
	value As Short _
) As Byte()
'Usage
Dim value As Short 
Dim returnValue As Byte()

returnValue = BitConverter.GetBytes(value)

Parameters

value
Type: System.Int16

The number to convert.

Return Value

Type: System.Byte()
An array of bytes with length 2.

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

' Example of the BitConverter.GetBytes( Short ) method. 
Imports System
Imports Microsoft.VisualBasic

Module GetBytesInt16Demo

    Const formatter As String = "{0,10}{1,13}" 

    ' Convert a Short argument to a Byte array and display it. 
    Sub GetBytesInt16( argument As Short )

        Dim byteArray As Byte( ) = BitConverter.GetBytes( argument )
        Console.WriteLine( formatter, argument, _
            BitConverter.ToString( byteArray ) )
    End Sub  

    Sub Main( )

        Console.WriteLine( _
            "This example of the BitConverter.GetBytes( Short ) " & _
            vbCrLf & "method generates the following " & _
            "output." & vbCrLf )
        Console.WriteLine( formatter, "Short", "Byte array" )
        Console.WriteLine( formatter, "-----", "----------" )

        ' Convert Short values and display the results.
        GetBytesInt16( 0 )
        GetBytesInt16( 15 )
        GetBytesInt16( -15 )
        GetBytesInt16( 10000 )
        GetBytesInt16( -10000 )
        GetBytesInt16( Short.MinValue )
        GetBytesInt16( Short.MaxValue )
    End Sub  
End Module 

' This example of the BitConverter.GetBytes( Short ) 
' method generates the following output. 
'  
'      Short   Byte array 
'      -----   ---------- 
'          0        00-00 
'         15        0F-00 
'        -15        F1-FF 
'      10000        10-27 
'     -10000        F0-D8 
'     -32768        00-80 
'      32767        FF-7F

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show: