Convert UInt16 to Byte Array

R

rawCoder

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
 
H

Herfried K. Wagner [MVP]

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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top