473,657 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Byte Ordering : Little endian - Big Endian : Binary Files

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
5 10021
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
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******** *************@h 48g2000cwc.goog legroups.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
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
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.co m>
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


"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
4927
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there any solid reasons to prefer text files over binary files files?
28
2776
by: wwj | last post by:
void main() { char* p="Hello"; printf("%s",p); *p='w'; printf("%s",p); }
5
3330
by: srikant | last post by:
I am writing a client in C# that needs to communicate over the network to a legacy C++ application that uses Unicode strings. I realize that C# strings are already in Unicode, however, how do I account for the network order transformation. Can I simply do the equivalent of string = "hello world"; // this is a unicode strings (2 bytes per char) bytes buffer = UnicodeEncoding.GetBytes(str); myNetworkStream.Write(buffer, 0, buffer.Length); ...
4
3684
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the following code that compiles OK. It runs and shows the requested output. However, after execution, it pops one of those windows to send error reports online to the porgram creator. I have managed to find where the error is but can't see what's wrong....
2
1368
by: ShihChun | last post by:
Hi everyone, I encounter a problem in writing binary files for Sun Solaris system. The problem is I have an array (data type: double) need to be ported from PC to Sun Solaris workstation. However, the binary files produced by fwrite will cause Sun read in wrong data Does anybody know how to solve it? Thanks a lot
33
3387
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a 4-byte value. Can I use the arithmatic shift operators to hide the endian-ness of the underlying processor when assembling a native 4-byte value like follows: unsigned int integerValue; unsigned char byteArray;
10
3637
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in binary mode. according to me, notepad opens files and each byte of the file read, it converts that byte from ascii to its correct character and displays
9
2876
by: deepakvsoni | last post by:
are binary files portable?
7
13047
by: apollo135 | last post by:
Dear all, Could someone please clarify and help with byte ordering macro (big/litte endian conversion)? I found thefollowinf macron on the internet but I have a doubt to use it ... ============ #if defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) #define htons(A) (A) #define htonl(A) (A) #define ntohs(A) (A) #define ntohl(A) (A)
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.