about BigEndian and LittleEndian

S

Sharon

hi all,

I generate binary text file (in Windows using Dev-C++)
Is the generated binary file using BigEndian?
Are there any method to generate binary file using LittleEndian?
Because I want the generated binary file to be used in Palm, is it necessary
to do so ?
thanks!
 
J

Joona I Palaste

Sharon <[email protected]> scribbled the following
I generate binary text file (in Windows using Dev-C++)
Is the generated binary file using BigEndian?

Mu.
"Endianness" only comes into play when you are treating multiple
consecutive bytes as a single number. In "binary text files", there
are no such numbers defined.
Or if there are, you didn't tell us how they are defined.
Are there any method to generate binary file using LittleEndian?

If it's strictly one-char-per-one-byte, then it is already both
LittleEndian and BigEndian.
Because I want the generated binary file to be used in Palm, is it necessary
to do so ?

If it's strictly one-char-per-one-byte, the exact same file will work
in both Windows and Palm.
 
M

Mark A. Odell

I generate binary text file (in Windows using Dev-C++)
Is the generated binary file using BigEndian?

This is not a C question, but since x86 PCs are little-endian you can bet
an executable image would be little-endian.
Are there any method to generate binary file using LittleEndian?

Not a C question but you get little-endian on x86 based PCs.
Because I want the generated binary file to be used in Palm, is it
necessary to do so ?

Not a C question. Depending upon how the Palm's processor is configured
you may need big or little-endian. If you don't know you won't succeed.
Try comp.arch.embedded where this might be slightly more topical.
 
M

Mark A. Odell

This is not a C question, but since x86 PCs are little-endian you can
bet an executable image would be little-endian.

Where did I get executable image? More coffee...
 
E

Eric Sosman

Sharon said:
hi all,

I generate binary text file (in Windows using Dev-C++)

What do you mean by a "binary text" file? C's I/O streams
operate in "text mode" or in "binary mode," and the two are
mutually exclusive: one or the other, but not both.
Is the generated binary file using BigEndian?

Perhaps, perhaps not. It depends on how you go about
"generating" it.
Are there any method to generate binary file using LittleEndian?

Yes. However, you seem so confused about more fundamental
issues that the explanation would probably be a waste of effort
at this point. Please review the notions of "binary" and "text"
streams, decide exactly what it is you want to do, and reformulate
your question accordingly.
Because I want the generated binary file to be used in Palm, is it necessary
to do so ?

I have no idea; sorry.
 
M

Martijn Lievaart

Where did I get executable image? More coffee...

A binary text file? That can only refer to an executable image. You were
right after all.

For those that don't know, 'text' is also use as a (terribly confusing)
term for the code of a program as it is layed out in an executable file or
in memory.

M4
 
M

Mark A. Odell

A binary text file? That can only refer to an executable image. You were
right after all.

For those that don't know, 'text' is also use as a (terribly confusing)
term for the code of a program as it is layed out in an executable file
or in memory.

Good point! .text is a typical name for the executable section of program.
Thanks.
 
M

Mike Y.

hi all,

I generate binary text file (in Windows using Dev-C++)
Is the generated binary file using BigEndian?
Are there any method to generate binary file using LittleEndian?necessary
to do so ?
thanks!

<<<<

You're targetting the Palm platform? Regardless of endian issues, the
binary image created for Windows won't run on a Palm. You might be
interested in the prc tool chain for Linux. Like Dev-C++, it's free:

http://www.palmos.com/dev/tools/gcc/

Okay, for fun and to keep this about C:

/* Returns 1 for little endian (e.g: Intel),
0 for big endian (e.g.:Motorola) */
int Endianness (void)
{
union
{
int anInteger;
char singleByte;
}endianTest;

endianTest.anInteger = 1;
return endianTest.singleByte;
}

This fragment was filched from Mongan and Suojanen's book, "Programming
Interviews Exposed."

--Mike Y.
 
G

glen herrmannsfeldt

Martijn Lievaart wrote:

(snip)
A binary text file? That can only refer to an executable image. You were
right after all.

For those that don't know, 'text' is also use as a (terribly confusing)
term for the code of a program as it is layed out in an executable file or
in memory.

IBM, at least, seems to like it. The S/360 object code files contain a
few different types of records, ESD (external symbol dictionary), RLD
(relocation dictionary), TXT (the instructions and data), and END (maybe
you can figure out that one). (There is a newer file format, but the
S/360 format is still in use.)

Under VM/CMS object files have the TEXT extension, and object libraries
are TXTLIB.

I suppose other systems also use similar names, but it can be confusing
sometimes.

-- glen
 
S

Sharon

EventHelix.com said:
Palm and Pentium families have different byte ordering. So you
will have to swap all 16, 32 and 64 bit numbers.

The following article should help:
http://www.eventhelix.com/RealtimeMantra/ByteAlignmentAndOrdering.htm
short and long convertion work fine, but how about double? any suggestion?

short convert_short(short in)
{
short out;
char *p_in = (char *) &in;
char *p_out = (char *) &out;
p_out[0] = p_in[1];
p_out[1] = p_in[0];
return out;
}

long convert_long(long in)
{
long out;
char *p_in = (char *) &in;
char *p_out = (char *) &out;
p_out[0] = p_in[3];
p_out[1] = p_in[2];
p_out[2] = p_in[1];
p_out[3] = p_in[0];
return out;
}
 
S

Sharon

Eric Sosman said:
What do you mean by a "binary text" file? C's I/O streams
operate in "text mode" or in "binary mode," and the two are
mutually exclusive: one or the other, but not both.

sorry i mean binary file
 
M

Martijn Lievaart

short and long convertion work fine, but how about double? any suggestion?

Doubles are not standarised by C or C++. You'll have to look at the
documentation for the source and target platform and see if this can at
all be done (easily) first. If both use the same format (most use IEEE),
it is a simple matter of looking at the docs for the respective
processors/platforms and/or writing some simple testprograms.

If both don't use the same format, search for some 3rd party lib to
convert from one format to the other, or write your own. Your, still stuck
with the endiannes then, but that should be a minor annoyance if you
really hit this problem.

HTH,
M4
 
E

EventHelix.com

double and floating point numbers are represented as
sign bit, followed by exponent and then the fraction part.

If the double is presented as a 64 bit number, swapping it
would be on the same lines as the swapping of a 64 bit integer.

Hope this helps.

Sandeep
 
J

Joona I Palaste

EventHelix.com <[email protected]> scribbled the following
double and floating point numbers are represented as
sign bit, followed by exponent and then the fraction part.

Says who?
If the double is presented as a 64 bit number, swapping it
would be on the same lines as the swapping of a 64 bit integer.

Says who?

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg
 
I

Irrwahn Grausewitz

Mr. Ger said:
Please speak English and not Finnish in English groups please.

'Mu' (at least in this case) isn't Finnish; it is a Zen reply,
with the approximate meaning: "The only way to know the answer
to this question is not asking this question.", or, in short:
"I am un-asking your question."

Regards
 

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

Members online

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,247
Latest member
GabrieleL2

Latest Threads

Top