PC Review


Reply
Thread Tools Rate Thread

Bigendian Vs littleendian

 
 
Craig Klinker
Guest
Posts: n/a
 
      10th Jan 2004
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


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      10th Jan 2004
Craig Klinker <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Craig Klinker
Guest
Posts: n/a
 
      10th Jan 2004
Thanks for the reply. I can write this but I thought I would check if
something already existed before doing it myself.

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Craig Klinker <(E-Mail Removed)> wrote:
> > 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.
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mySqlBytes.buffer is getting converted to BigEndian even though both SQL server 2005 and the CLR function are on the same machine which shows BitConverter.IsLittleEndian == true DR Microsoft ADO .NET 1 9th Jan 2008 11:10 AM
mySqlBytes.buffer is getting converted to BigEndian even though both SQL server 2005 and the CLR function are on the same machine which shows BitConverter.IsLittleEndian == true DR Microsoft Dot NET Framework 6 8th Jan 2008 12:20 PM
littleEndian/bigEndian =?Utf-8?B?ZG9jc2NobmlwcA==?= Microsoft C# .NET 19 10th Jul 2006 04:11 AM
Reading bytes from BigEndian TF Microsoft Dot NET 3 15th Jun 2004 05:04 PM
BinaryReader -- can it be forced to read a BigEndian stream Laszlo Szijarto Microsoft C# .NET 14 28th May 2004 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 AM.