Reading Single and Double reals in Little-endian and Big-endian
- To: mathgroup at smc.vnet.net
- Subject: [mg125003] Reading Single and Double reals in Little-endian and Big-endian
- From: ezh <dgolber at aol.com>
- Date: Fri, 17 Feb 2012 06:25:18 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
I am running Mathematica 4 on a PC. I am reading a file (an STL file), which has 32-bit integers and 32- bit reals in little-endian format. I can read in the integers correctly, using numTriangles = ReadBinary[strm, Int32, ByteOrder -> LeastSignificantByteFirst]; However, the documentation states (and is correct) that ByteOrder -> LeastSignificantByteFirst only affects reading integers. So far, I have not figured out how to read 32-bit reals ("Single") correctly. I could read in the 32-bits as bytes, and reverse the order, and build a 32-bit integer with the correct bits in it to be the desired 32-bit real. But how do I get Mathematica to regard those 32-bits as an IEEE real number? I'd hate to have to read up on the IEEE format and build the value myself. I can't be the first person in theworld to hit this problem! And why (futile question) doesn't mathematica know about big- and little-endian for _reals_ as well as for _integers_? Thanks Dave Golber