Read long int from binary file

Peter Hansen peter at engcorp.com
Tue Oct 14 12:28:43 EDT 2003


Enrico Morelli wrote:
> 
> I have to write a program which reads from a binary file, a serious of
> 32 bit long integer data and stores its in an array.
> I cannot know the format (little or big endian) and I have to perform the
> properly 4 byte reverse order swapping.

Do you really mean that you must support both formats?  In other words,
that you can't *hardcode* the choice of format, but must support either
one?  (Presumably based on some command-line option, or information that
is contained elsewhere but which is available at program runtime.)

I'm guessing the confusion results from uncertain English usage... One
would normally say "I do not know the format (in advance)" rather than
"I cannot know the format".  If you really mean you *cannot* know, then
why would you expect that the computer "could" know something you cannot?

-Peter




More information about the Python-list mailing list