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: email@example.com
- References: <firstname.lastname@example.org> <email@example.com>
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.