By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 2,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

Byte Ordering : Little endian - Big Endian : Binary Files

P: n/a
Greetings,

How does one find the format of a binary file to be in Little Endian or
big Endian before we start reading the file.

Thanks

Jul 9 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
mo************@gmail.com wrote:
Greetings,

How does one find the format of a binary file to be in Little Endian or
big Endian before we start reading the file.
You have to know the format of the file. There have to be some marker
bytes included in the file somewhere, that tell the endianess. Like the
"Byte Order Mark"s in Unicode files. Cannot tell you more without
knowing what kind of files you are talking about.

hth,
Max
Jul 9 '06 #2

P: n/a
A binary file is simply a sequence of 1s and 0s. The File System entry will
have some information about the file regarding its length, location, file
attributes, permissions, etc., but the actual contents of the file itself
can be anything. You must know what the structure of the file is in order to
be able to read it at all.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
<mo************@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Greetings,

How does one find the format of a binary file to be in Little Endian or
big Endian before we start reading the file.

Thanks

Jul 9 '06 #3

P: n/a
Hi Max,

I am trying to read dicom file.
The preamble and the prefix of the file are by default in little
endian.

After that the file is supposed to have tags followed by data.
ex: (0002) - value length - actual data
(0810) - value length - actual data

When we use the binaryreader , it reads the bytes in as is sequence
however when i use the Readint16 the order of the bytes is reversed.
ex: 02 00 would be read as 0002 when readint16 is used.

-Masood

Markus Stoeger wrote:
mo************@gmail.com wrote:
Greetings,

How does one find the format of a binary file to be in Little Endian or
big Endian before we start reading the file.

You have to know the format of the file. There have to be some marker
bytes included in the file somewhere, that tell the endianess. Like the
"Byte Order Mark"s in Unicode files. Cannot tell you more without
knowing what kind of files you are talking about.

hth,
Max
Jul 9 '06 #4

P: n/a
Masood <mo************@gmail.comwrote:
I am trying to read dicom file.
The preamble and the prefix of the file are by default in little
endian.

After that the file is supposed to have tags followed by data.
ex: (0002) - value length - actual data
(0810) - value length - actual data

When we use the binaryreader , it reads the bytes in as is sequence
however when i use the Readint16 the order of the bytes is reversed.
ex: 02 00 would be read as 0002 when readint16 is used.
If you want to read using a specific endianness, see
http://www.pobox.com/~skeet/csharp/miscutil

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 9 '06 #5

P: n/a


"Masood" wrote:
Hi Max,

I am trying to read dicom file.
The preamble and the prefix of the file are by default in little
endian.
You are partially right. Make sure you've read PS3.10 2006, 7.1, esp. page 22.

You have to read the META information tags. When you match
the (0002,0010) tag, you'll find a UI Data Element. Extract the UID
using the current text encoding and store the announced syntax
to your reader after the group is finished. Group 0002 has a defined
Group Length ( "(0002,0000)") so you know when it is finished.

When you read beyond the meta group ( that many bytes that
are being announced) you "switch" your encoding.
>
After that the file is supposed to have tags followed by data.
ex: (0002) - value length - actual data
(0810) - value length - actual data
Are you sure you read PS3.5 2006? That is not a DICOM Data Element
Description (missing Tag Number and Value Representation (explicit
during meta data at least).
>
When we use the binaryreader , it reads the bytes in as is sequence
however when i use the Readint16 the order of the bytes is reversed.
ex: 02 00 would be read as 0002 when readint16 is used.
That is right.

You shouldn't use Binaryreader. Do your own, since you
need to switch. There is also a good library from John Skeet,
that already answered you.
best
doc

Jul 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.