Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Stefan Schwarzer <sts@boa.ica1.uni-stuttgart.de>
Subject: Re: Binary File Format Inter-operatability ?
Date: 2000/07/09	[thread overview]
Message-ID: <8ka015$prs$1@infosun2.rus.uni-stuttgart.de> (raw)
In-Reply-To: 39654780.55F16F6A@hyundai-motor.com

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




      reply	other threads:[~2000-07-09  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-07  4:00 Binary File Format Inter-operatability ? Hyuntaek Hong
2000-07-09  4:00 ` Stefan Schwarzer [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox