Bigendian Vs littleendian

  • Thread starter Thread starter Craig Klinker
  • Start date Start date
C

Craig Klinker

I am having an issue trying to use a binary reader. In the following case I
would like to have the value 66 and 3 returned respectivly but I am getting
large number since the reader is reading in littleendian format.

Here is my code

Dim Buffer() As Byte = New Byte() {&H0, &H0, &H0, &H42, &H0,
&H0, &H0, &H3}
Dim ms As New IO.MemoryStream(Buffer)
Dim br As New IO.BinaryReader(ms,
Text.Encoding.BigEndianUnicode)
Console.WriteLine("Message Length = " & br.ReadInt32())
Console.WriteLine("Message Type = " & br.ReadInt32())

This generates

Message Length = 1107296256
Message Type = 50331648



Does anyone know of an easy way to accomplish this or so I have to write my
own encoder?



Thanks
Craig J. Klinker
IntraNext Systems
 
Craig Klinker said:
I am having an issue trying to use a binary reader. In the following case I
would like to have the value 66 and 3 returned respectivly but I am getting
large number since the reader is reading in littleendian format.

Here is my code

Dim Buffer() As Byte = New Byte() {&H0, &H0, &H0, &H42, &H0,
&H0, &H0, &H3}
Dim ms As New IO.MemoryStream(Buffer)
Dim br As New IO.BinaryReader(ms,
Text.Encoding.BigEndianUnicode)
Console.WriteLine("Message Length = " & br.ReadInt32())
Console.WriteLine("Message Type = " & br.ReadInt32())

This generates

Message Length = 1107296256
Message Type = 50331648



Does anyone know of an easy way to accomplish this or so I have to write my
own encoder?

Basically you need a version of BinaryReader which allows you to
specify the endianness. I've considered writing such a class before -
if you'd like me to do it for you, just let me know.
 
Thanks for the reply. I can write this but I thought I would check if
something already existed before doing it myself.
 
Back
Top