473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

(To .Net Develpers and not only) Don't know what to think with byte ordering and similar

Can anyone halp me with some questions?
Is there multiplatform standart in binary representation of primitive
datatypes when you writing it through BinaryWriter?

In other words if I write by BinaryWriter for example Int64 or Single, can I
without problem read it by BinaryWriter on platform with different (from
Intel x86) byte order?

If yes, then BinaryWriter and BinaryReader implementation will be different
than in .Net Framework for Windows.
Am I right?

My general problem (as I think) in rashness with data types binary
convertions in .Net Framefork. Using BitConverter class too expensive for
perfomanse :-(. I just don't understend it!!! Why it always returns new
arrays!? Why it can't copy binary types to buffer array? Why I can't see
converting to and from decimal ty bytes? Greate. There is only public
convertion from bytes to decimal, but no public from decimal to bytes (there
is only internal convertion from decimal to bytes and it only can be
accessed by BinaryWriter). Convertion from Guid to bytes exitst, but it
return new array and it's implementation produces new arrays (it uses
BitConverter).

I think that each privitive, elementary and structure type (which potentialy
required often to be stored in files (binary data)) have to have common
design to provide effective that functionality (from binary and to binary).
And it must not depends at platform (in terms processor architecture and
similar).

Please, let this letter to read someone form .Net developer team.
And sorry for my bad English.

I hope I'll see changes in feature version .Net Framework.
Jul 21 '05 #1
4 1729
Vladimir <xo***@tut.by> wrote:
Can anyone halp me with some questions?
Is there multiplatform standart in binary representation of primitive
datatypes when you writing it through BinaryWriter?
Not with .NET, no.
In other words if I write by BinaryWriter for example Int64 or Single, can I
without problem read it by BinaryWriter on platform with different (from
Intel x86) byte order?
Quite possibly not.
If yes, then BinaryWriter and BinaryReader implementation will be different
than in .Net Framework for Windows.
Am I right?
Surely you mean the implementation will be the same...
My general problem (as I think) in rashness with data types binary
convertions in .Net Framefork. Using BitConverter class too expensive for
perfomanse :-(. I just don't understend it!!! Why it always returns new
arrays!? Why it can't copy binary types to buffer array? Why I can't see
converting to and from decimal ty bytes? Greate. There is only public
convertion from bytes to decimal, but no public from decimal to bytes (there
is only internal convertion from decimal to bytes and it only can be
accessed by BinaryWriter). Convertion from Guid to bytes exitst, but it
return new array and it's implementation produces new arrays (it uses
BitConverter).
Actually, I can't see anything for going from decimal to bytes to start
with. You can use Decimal.GetBits() and new Decimal(int[]) though.
I think that each privitive, elementary and structure type (which potentialy
required often to be stored in files (binary data)) have to have common
design to provide effective that functionality (from binary and to binary).
And it must not depends at platform (in terms processor architecture and
similar).

Please, let this letter to read someone form .Net developer team.
And sorry for my bad English.

I hope I'll see changes in feature version .Net Framework.


I have a few classes which I haven't finished or tested yet but wrote
when waiting for an eye operation. They're basically
EndianBitConverter, EndianBinaryWriter and (as yet unwritten)
EndianBinaryReader. They allow you to specify which endianness to use.

Let me know if you'd like a copy of the classes so far...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
In other words if I write by BinaryWriter for example Int64 or Single, can I
without problem read it by BinaryWriter on platform with different (from
Intel x86) byte order?


Quite possibly not.


It looks like I'm wrong about this - MSDN at least specifies that
BinaryWriter will use little-endian format, always. The BinaryReader
docs also claim it "stores" the data in little-endian format, which I
take to mean it reads the data in little-endian format.

Not always ideal, but at least it's reliable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
Yea...
And what about Buffer.BlockCopy()?
Jul 21 '05 #4
> It looks like I'm wrong about this - MSDN at least specifies that
BinaryWriter will use little-endian format, always. The BinaryReader
docs also claim it "stores" the data in little-endian format, which I
take to mean it reads the data in little-endian format.

Not always ideal, but at least it's reliable.


May be code like that is platform independed?

/*
public virtual void Write(int value)
{
this._buffer[0] = ((byte) value);
this._buffer[1] = ((byte) (value >> 8));
this._buffer[2] = ((byte) (value >> 16));
this._buffer[3] = ((byte) (value >> 24));
this.OutStream.Write(this._buffer, 0, 4);
}
*/

I just don't know how realy how generaly shif operators useful?
When, and how about it speed and dedication.
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Farooq Khan | last post by:
hi, my development team has been assigned a project that involves writing our own Web service. i happen to be a C++ programmer, new to C#/ASP.net. i dont know where to begin with......any...
2
by: Pavel Novotny | last post by:
H I'm trying to import a | seperated text from string variable which represents a tabl with several fields, eg 6124079|PRIRUBA 11 DN250 PN6;CSN131160.0;11369.1;CSN131005.50|KS|11,100000|3437,...
5
by: srikant | last post by:
I am writing a client in C# that needs to communicate over the network to a legacy C++ application that uses Unicode strings. I realize that C# strings are already in Unicode, however, how do I...
33
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a...
0
by: arunavlp | last post by:
hi, I am new to .net , i am using VB.Net (Web form). I dont know how to pass parameters to stored function. Regards, Arun.S
2
by: hojjatnikan | last post by:
please help me this code 62EH&5gx0wiqoQFw is this name ( Belux) but i dont know how convert it i dont know the algorithm of this code plead help me
2
by: Tiruak | last post by:
Hi there. Thanks in advance for the people reading and trying to help. I'm very begginer using flash and action script, and I tryed to do this one navigation menu. Since I dont have experience...
7
by: apollo135 | last post by:
Dear all, Could someone please clarify and help with byte ordering macro (big/litte endian conversion)? I found thefollowinf macron on the internet but I have a doubt to use it ... ============...
2
by: Sreenivas | last post by:
I dont know how to compile cpp programs with gcc as i am new to gcc and cpp. could anybody help me out? Thanks&Regards, Srinivas Reddy Thatiparthy.
2
by: shwetaT | last post by:
i m working in php domain and i dont know much about php,so will u plz suggest me some good sites through which i learn php very well n fast
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.