MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reading Single and Double reals in Little-endian and Big-endian

  • To: mathgroup at smc.vnet.net
  • Subject: [mg125149] Re: Reading Single and Double reals in Little-endian and Big-endian
  • From: ezh <dgolber at aol.com>
  • Date: Fri, 24 Feb 2012 01:00:02 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jhldir$ot7$1@smc.vnet.net> <jhsu7g$np4$1@smc.vnet.net>

Yes, it's an old Mathematica.  I pay for it myself, that's why.

Yes, I need to reverse the byte order.  After all, it's not a PC
storing the stuff read from the file, it's Mathematica.  In any case,
this is not a theoretical statement.  I tried it

Here's the work-around I developed:

strm1= open orginal file for input
strm2= open "reversed' file for output.
copy the strm1 file to the strm2 file, but
At each 4-byte floating number in the input file:
stuff=ReadBinaryList[strm1,Byte,4]
WriteBinary[strm2,Reverse[stuff],ByteConversion -> (ToBytes[#,
IntegerConvert -> Byte] &)]
Now close the files.
The "reversed" file is the same as the original file, but with each 4-
byte floating number in the opposite byte order

Now open the "reversed" file for binary input.
Now
value=ReadBinary[strm,Single];
gets the right value.



  • Prev by Date: Re: Dynamically finding distances and angles between user-specified points
  • Next by Date: Re: Complex and Solve
  • Previous by thread: Re: Reading Single and Double reals in Little-endian and Big-endian
  • Next by thread: Re: Reading Single and Double reals in Little-endian and Big-endian