Byte Ordering : Little endian - Big Endian : Binary Files

M

mohamed.alam78

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
 
M

Markus Stoeger

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
 
K

Kevin Spencer

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.
 
M

Masood

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
 
J

Jon Skeet [C# MVP]

Masood said:
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
 
G

Guest

Masood said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top