Does the C# language (or IL) make any guarantees as to
the
No. But if you really need to know (which should be relatively rare)
you can use the Bitconverter.IsLittelEndian field to determine the
underlying architecture.
Ah, thanks. I'm unmarshaling a little-endian byte stream
and need to turn the data in the byte stream back into
real things, such as floats and ints. So, when I'm running
on a big-endian machine, I have to change the byte order
accordingly.
BitConverter is close to what I need. But, what do I do
when I'm running on a big-endian machine and need to
convert a little-endian byte stream? From what I can see,
there is no way to tell BitConverter what byte order the
array is in that is to be converted.
And, of course, I need to be able to do the opposite:
convert C# value types into a little-endian byte stream
(whether I'm running on a little-endian or big-endian
machine). Is there any class that does the inverse of what
BitConverter does?
I assume that the other BitConverter methods would take the endianness
into account (it doesn't seem to be explicitly documented in the SDK),
to make converting blobs of bytes (in byte arrays) to .NET native types
easy.
Well, as far as I can see, there is no way to specify the
byte order of the byte array.
On the down-side, as far as I can tell BitConverter is not part of the
ECMA CLI standard, so it might not exist on a Mono (or other non-MS)
runtime for all I know.
Aha. Thanks for pointing that out. I guess I can always
write it myself (but I don't see a way to do this without
having to resort to pointers and unsafe code.
What I'm really looking for is something along the lines
of java.nio.ByteBuffer.
Cheers,
Michi.