Convert UInt16 to Byte Array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rawCoder

    Convert UInt16 to Byte Array

    Hi,

    Ok this shud b simple but i cant seem to find it.

    I want to convert a System.UInt16 data to 2 Byte array and System.UInt32
    data to 4 Byte array ( BigEndian)

    something like
    Public Sub GetBytes(ByVal n as System.UInt16, ByRef b As Byte())
    'Converts the System.UInt16 to a 2 Byte array
    void GetBytes( n System.UInt16, Byte b[] )
    // Converts the System.UInt16 to a 2 Byte array
    * ( UnCompiled)

    Sorry if i am asking for a spoon feed :-)

    Thanx,
    rawCoder


  • Herfried K. Wagner [MVP]

    #2
    Re: Convert UInt16 to Byte Array

    "rawCoder" <rawCoder@hotma il.com> schrieb:[color=blue]
    > I want to convert a System.UInt16 data to 2 Byte array and System.UInt32
    > data to 4 Byte array ( BigEndian)[/color]

    'BitConverter.G etBytes' provides an overload for 'UInt16'/'UInt32', but on
    Windows it will work in Little Endian format only. Jon Skeet [MVP] provides
    a class named 'EndianBitConve rter' that can be used with Big and Little
    Endian format:

    Miscellaneous Utility Library
    <URL:http://www.yoda.arachs ys.com/csharp/miscutil/>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    Working...