From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,352a9ab38f62b512 X-Google-Attributes: gidfa528,public From: Stefan Schwarzer Subject: Re: Binary File Format Inter-operatability ? Date: 2000/07/09 Message-ID: <8ka015$prs$1@infosun2.rus.uni-stuttgart.de>#1/1 X-Deja-AN: 644241115 References: <39654780.55F16F6A@hyundai-motor.com> Organization: ICA 1, Stuttgart University User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (SunOS/5.7 (sun4u)) Newsgroups: comp.unix.tru64 Hyuntaek Hong 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