Big/Little Endian - Changing?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Big/Little Endian - Changing?

Kenneth Jacker-2
I use 'octave' to produce 16-bit binary values on one machine and use
another machine to process those binary values.  The binary format is
both convenient and fast.

Unfortunately, the "endianess" of the two machines is different.

Of course, I have written a small program (using the common swab()
library function) in C to perform what some call the needed "sex change".

Question:  how can I do this solely within (e.g., without needing an
additional program) 'octave'?  If I can find a way, this will save one
step in my work.

Thanks for any ideas!

-Prof Kenneth H Jacker      Internet:   [hidden email]
-Computer Science Dept        Bitnet:   jackerkh@appstate
-Appalachian State Univ
-Boone, NC  28608  USA           URL:   http://www.cs.appstate.edu/~khj

Reply | Threaded
Open this post in threaded view
|

Big/Little Endian - Changing?

John W. Eaton-6
On 26-Mar-1997, Kenneth Jacker <[hidden email]> wrote:

| I use 'octave' to produce 16-bit binary values on one machine and use
| another machine to process those binary values.  The binary format is
| both convenient and fast.
|
| Unfortunately, the "endianess" of the two machines is different.
|
| Of course, I have written a small program (using the common swab()
| library function) in C to perform what some call the needed "sex change".
|
| Question:  how can I do this solely within (e.g., without needing an
| additional program) 'octave'?  If I can find a way, this will save one
| step in my work.

Yes, Octave 2.x can swap the bytes for you when it reads the data.
Look at the documentation for the ARCH parameter for fopen, fread, and
fwrite.  For example,

  f = fopen ("foo", "r", "ieee-le");

opens the file `foo' for reading assuming the data format is little
endian with IEEE floating point, independent of the byte order of the
machine on which Octave is running.

The fread and fwrite functions also include an ARCH parameter that
allows you to override the default format specified when the file was
opened.

jwe