[ale] Re: binary data format (fwd)
Joe
jknapka at mindspring.com
Thu Mar 7 11:40:54 EST 1996
}> >What is the difference between the binary formats on a Sun Sparc
}> >and a Linux system? I have a bunch of binary data that was written
}> >on a Sparc, but I can't get anything but gibberish when I try
}> >to read it on my Linux system. How can I convert the data to
}> >be read by the Linux system?
}>
}> It may be the representation of the actual data, referred to as little
}> endian vs. big endian. Basically every other byte is swapped. The
Unfortunately, it is not that simple. You can't reliably convert a file
from one endian-ness to the other unless you know what order the data
items were written in, and what types they are. For ex., if I do
outfile << 'a' << 'b' << 'c' << 'd' << (long)1;
on an intel box, the binary data in the file is \a\b\c\d\0x01\0x00\0x00\0x00.
If you assumed it was just a sequence of 4 2-byte shorts and re-endianized
it on that basis, you'd end up with \b\a\d\c\0x00\0x01\0x00\0x00, so on my
68000 box I read it in and get
char a,b,c,d; long l;
cin >> a; // a == 'b'
cin >> b; // b == 'a'
cin >> c; // c == 'd'
cin >> d; // d == 'c'
cin >> l; // l = 0x00010000
which is totally wrong.
I can't really see how you could make a program that would do the job
you weem to want in a general way; you will probably need to do something
like
(1) Load the original binary file into the program that created it, on
the machine where it was generated;
(2) Save it out in some portable form, like ASCII text;
(3) Load it up on the target platform.
Of course, if you know that the file really is just a sequence of
longs, for example, then you can do the naive thing and it will
work.
-- Joe
More information about the Ale
mailing list