IEEE single precision number.

*To*: mathgroup at smc.vnet.net*Subject*: [mg51782] IEEE single precision number.*From*: Vangelis Marinakis <V.Marinakis at damtp.cam.ac.uk>*Date*: Tue, 2 Nov 2004 02:05:02 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Dear everyone, Looking at the internet I found this email: ***************************************************************** Hi, I want to convert a group/stream of Bytes to various internal Mathematica numerical types, particularly into Real (machine precision number). The motivation is the fast reading of binary files. I don't want to deal with the Std Package Utilities`BinaryFiles`ReadBinary or Developer'BinaryImport, which do have the conversion utilities (e.g. into Real32, etc), since they are SLOW or otherwise clunky. When employing the suggested fast reading of binary files: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ There are numerous means of reading data into Mathematica from binary files. However, most of them are too slow. Through experience and some newsgroup research, I've found the fast easy way: stream = OpenRead["Cals9", DOSTextFormat -> False]; (* Note: this DOSTextFormat->False option is key to using ReadList[] in binary mode; otherwise, it wants to digest text. Readin Byte chunks, then post-format. Remarkably, the DosTextFormat option is not mentioned/discussed anywhere in the Mathematica book or Help Browser *) SetStreamPosition[stream, 78*131072]; (* Position to desired read starting location within file...count is in Bytes, and is index base = 0 *). data = ReadList[stream, Byte, 131072]; (* Reads 131072 Bytes into linear List "data" *) Close[stream]; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ you end up with a list of Bytes. Converting it to 16-bit integers is easy: data = Map[(#1[[1]] + 256*#1[[2]] & ), Partition[data, 2]]; (* takes original Byte List "data" and makes 16-bit "words", writing over List "data". Result is half-as-long List of words. *) ...but how would one convert it to real numbers (given that every 4 bytes comprises an IEEE single-precision number)? Thanks. franki at aerodyne.com ***************************************************************** Does anyone no the answer, because I have exactly the same problem! Thanks. Vangelis Marinakis.

**Follow-Ups**:**Re: IEEE single precision number.***From:*János <janos.lobb@yale.edu>

**Re: IEEE single precision number.***From:*Yasvir Tesiram <tesiramy@omrf.ouhsc.edu>