Re: Reading Single and Double reals in Little-endian and Big-endian
- To: mathgroup at smc.vnet.net
- Subject: [mg125155] Re: Reading Single and Double reals in Little-endian and Big-endian
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sat, 25 Feb 2012 01:53:58 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jhldir$ot7$1@smc.vnet.net> <jhsu7g$np4$1@smc.vnet.net> <ji794s$hcs$1@smc.vnet.net>
On 24/02/2012 06:02, ezh wrote: > 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. > I wonder if you would be eligible for this license: http://www.wolfram.com/mathematica/how-to-buy/hobbyist.html David Bailey http://www.dbaileyconsultancy.co.uk