Re: Converting integers to Big Endian Bytes

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.
 
H

Herfried K. Wagner [MVP]

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
 
M

Mike D Sutton

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/
 
J

Jeremy Cowles

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.
 
C

Chad Myers

(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
 

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