Re: Converting integers to Big Endian Bytes

  • Thread starter Thread starter Govind
  • Start date Start date
G

Govind

Hi All,

I want to Convert 32 bit integers in to big endian byte order.. The
default is Little Endian Format..

The method is :: BitConverter.GetBytes(IntVal)

Any method is in .NET for Big Endian pls let me know...


Regards,
Govind.
 
Hello,

Rick Rothstein said:
Almost everybody here is using VB6 or lower.

Almost everybody _here_ is using VB .NET.

IMO the question whould be posted in the framework ng only:

news://news.microsoft.com/microsoft.public.dotnet.framework

Untested:

\\\
Dim i As Integer = 12345656
Dim abyt() As Byte = BitConverter.GetBytes(i)
If BitConverter.IsLittleEndian Then
Array.Reverse(abyt)
End If
///

HTH,
Herfried K. Wagner
 
Almost everybody here is using VB6 or lower.
Almost everybody _here_ is using VB .NET.

This is what happens when people cross-post to multiple unrelated groups -
Depending on what group you're reading this in you could be writing VB
(Classic), VB.NET, C#, or any of the other .NET languages. Rick's response
was a generic .NET one given in the VB (Classic) groups, but should have
removed the .NET related groups from follow-up to avoid these kinds of
problems.

Mike


- Microsoft Visual Basic MVP -
E-Mail: (e-mail address removed)
WWW: Http://www.mvps.org/EDais/
 
This is the problem with cross posting, the person who posted this should
have his fingers slowly eaten off and his eyes pecked out by by buzzards.
 
(VB group removed)
See below for reply

Govind said:
Hi All,

I want to Convert 32 bit integers in to big endian byte order.. The
default is Little Endian Format..

The method is :: BitConverter.GetBytes(IntVal)

Any method is in .NET for Big Endian pls let me know...

All you have to do is:

byte[] buffer = BitConverter.GetBytes(intVal)

Array.Reverse(buffer);

// buffer is now BigEndian

-c
 
Back
Top