Read long int from binary file
Phil Stracchino
alaric at caerllewys.net
Tue Oct 14 12:28:53 EDT 2003
On Tue, Oct 14, 2003 at 12:19:25PM -0400, John Roth wrote:
> "Enrico Morelli" <enrico_morelli at yahoo.com> wrote in message
> news:pan.2003.10.14.15.37.50.602541 at yahoo.com...
> > 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.
>
> As a general rule, the problem is unsolvable. However, there are
> two practical special cases. One is that you may be able to determine
> based on the source of the file; different computers and different
> protocols have specific requirments.
Is it feasible for you to have a known value placed at the start of the
file as a "magic" number that you can use for endianness detection?
--
.********* Fight Back! It may not be just YOUR life at risk. *********.
: phil stracchino : unix ronin : renaissance man : mystic zen biker geek :
: alaric at caerllewys.net : alaric-ruthven at earthlink.net : phil at latt.net :
: 2000 CBR929RR, 1991 VFR750F3 (foully murdered), 1986 VF500F (sold) :
: Linux Now! ...Because friends don't let friends use Microsoft. :
More information about the Python-list
mailing list