|
-
October 30th, 2009, 05:12 AM
#1
how to open file and read as little-endian or big-endian
Hi,
Can anyone tell me how to open a binary file and read as either little or big endian using c#.
Any website or sample code that i can refer to???
Thanks in advance.
-
October 30th, 2009, 11:37 AM
#2
Re: how to open file and read as little-endian or big-endian
I think you will have to manage it by yourself. You could read the file into a byte[] then convert it to whatever you need; short[] or integer[].
This method produce an integer from a byte array that contains an integer formatted in big endian. The method assumes a 4 bytes array.
public int ConvertByteArrayToInteger(byte[] bInteger)
{
if (BitConverter.IsLittleEndian == true)
Array.Reverse(bInteger);
return BitConverter.ToInt32(bInteger, 0);
}
-
October 30th, 2009, 11:40 AM
#3
Re: how to open file and read as little-endian or big-endian
I forgot...
To read a binary file, use the System.IO.BinaryReader class. Very simple.
-
October 30th, 2009, 03:21 PM
#4
Re: how to open file and read as little-endian or big-endian
why would it's endianness be different than everything else?
-
October 31st, 2009, 02:05 PM
#5
Re: how to open file and read as little-endian or big-endian
I had to read raw database files that were produced on a Palm and the type of CPU uses by this system stores variables in the big-endian format.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|