System.BitConverter on Big-Endian-Platforms

  • Thread starter Thread starter Stefan Mecke
  • Start date Start date
S

Stefan Mecke

Hi all!

Could anyone please verify and post the behavior with MS.NET compact
framework on a big-endian system? The docs I found are not precise about
whether BitConverter always returns the platforms native endianness or
always little-endian like x86.

Thanks
Stefan Mecke

--------------------------------------------------------
using System;

public class Test
{
public static void Main(string[] args)
{
if (!BitConverter.IsLittleEndian){
byte[] ba;
int i4 = 45555;

ba = BitConverter.GetBytes(i4);

for (int i=0; i<ba.Length; i++)
{
Console.Write(" {0:x}", ba);
}
Console.WriteLine();
} else {
Console.WriteLine("Little-endian-platform -- doesn't help");
}
}
}
 
If you have need to read data produced by a big-endian system (such as a Palm database file), you might do as I did under the same circumstances. I read the data into bytes arrays one field/value at a time and manually reversed the bytes in the array. I then passed the reversed bytes into bitconverter. I have had no trouble reading Palm databases this way for quite a while.
 
That's what i do as well.

Steven said:
If you have need to read data produced by a big-endian system (such as a
Palm database file), you might do as I did under the same circumstances. I
read the data into bytes arrays one field/value at a time and manually
reversed the bytes in the array. I then passed the reversed bytes into
bitconverter. I have had no trouble reading Palm databases this way for
quite a while.
 
Ah! Can't see the forest for the trees, sorry.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Steven said:
If you have need to read data produced by a big-endian system (such as a
Palm database file), you might do as I did under the same circumstances. I
read the data into bytes arrays one field/value at a time and manually
reversed the bytes in the array. I then passed the reversed bytes into
bitconverter. I have had no trouble reading Palm databases this way for
quite a while.
 
Back
Top