If you know that the only difference is byte order (and not bit order), you can just juggle the bytes manually. As an example, a file generated on my x86 (little-endian) box:
$ perl -we 'my $pi = 4*atan2(1,1); print pack "f", $pi' > le-pi.bin $ od -h le-pi.bin 0000000 0fdb 4049 0000004
To read that in on my ppc (big-endian) system, I can do:
$ perl -we 'my $buf; read STDIN, $buf, 4; my $pi = unpack "f", reverse $buf; print "pi=$pi\n";' < le-pi.bin pi=3.14159274101257
Doing this to just one part of a larger buffer just takes a bit more imagination (although the fact that substr can be used as an lvalue might make it amusing. Untested, but does this work?)
# reverse endianness of first 4-byte float: substr( $buf, 0, 4 ) = reverse substr( $buf, 0, 4 );
In reply to Re: Unpacking Floating Point on architectures with different endians
by tkil
in thread Unpacking Floating Point on architectures with different endians
by HaveBlue
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |