* Re: Binary File Format Inter-operatability ?
2000-07-07 4:00 Binary File Format Inter-operatability ? Hyuntaek Hong
@ 2000-07-09 4:00 ` Stefan Schwarzer
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Schwarzer @ 2000-07-09 4:00 UTC (permalink / raw)
Hyuntaek Hong <hthong@hyundai-motor.com> wrote:
> I'm system administrator for SGI,DIGITAL,IBM-SP2..
> Some of my users complain IRIX can't read Compaq's making Binaryfiles.
> I just know that's because difference btw Little Endian and Big Endian
> ( File Support ).
> Any body has good conversion utility or advices ?
In general, you cannot convert binaries from little endian to big endian or
vice versa if you do not have the information how many bytes the stored
data items comprise (how can you tell a 32 bit integer from two 16 bit ones).
Worse, the sizes may differ between architectures and compilers.
Even worse, some (notably FORTRAN) compilers put additional formatting
information into binary files.
If your users work with FORTRAN though, I remember that in old days, DEC
FORTRAN had an option to convert data from little to big endian. Since
FORTRAN has portable data type sizes, and when reading the size of the read
items is known, there is a fair chance for this to work.
In C type languages, one can still convert the data 'by hand' when it
is read or written. Either one uses the xdr Routines (man pages) to
convert to 'network representation' or one does the necessary
conversion oneself. I have long used a short C program in some of my
programs, where I knew I was exchanging between platforms with
matching length of the C data types (see below)
I know that's not a lot, but maybe it can help in some cases ;)
Stefan
void byteorder ( void *array, int size, int nitems )
{
/* changes byteorder in place */
int i, ib;
int size_h, size_m;
unsigned char *current;
unsigned char temp;
size_h = size >> 1;
size_m = size - 1;
current = (unsigned char *) array;
for (i=0; i < nitems; current += size, i++ )
{
for ( ib=0; ib< size_h; ib++ )
{
temp = current[ib];
current[ib] = current[size_m - ib];
current[size_m - ib] = temp;
}
}
return;
}
--
Stefan Schwarzer office: +49-(0)711-685-7606 fax: x-3658
Uni Stuttgart, ICA 1 (?-
Pfaffenwaldring 27 //\ sts@ica1.uni-stuttgart.de
70569 Stuttgart, Germany -V_/---- http://www.ica1.uni-stuttgart.de/~sts
^ permalink raw reply [flat|nested] 2+ messages in thread