I guess you may read the 4 bytes as integer, then bitwise and (17 b.)
with mask of suitable bit pattern, then bitwise shift (33 b. or 34 b.)
to obtain the mantissa and exponent. 

On Sun, 23 Aug 2009, PackRat wrote:
> Ric Sherlock wrote:
> > > From: emptist
> > > In q I've learned to read a kind of binary
> > > formatted historical price data file, which contains 8 4 byte int
> > > data for each record, using: ...
> > 
> > Putting together the nicely broken down steps that Roger gave, a J
> > translation of the above line of q is: 
> >    _8]\ _2(3!:4) 1!:1 <'path/filename'
> 
> How would you do this with 4-byte Metastock (Computrac) data, which is 
> a floating point number in the old Microsoft Binary Format (MBF), which 
> was used in the original IBM PC's BASICA, GWBASIC, and QuickBASIC and 
> is different from the now-standard IEEE floating point format (which J 
> uses)?  
> 
> I recently purchased some historical market data which turned out to be 
> in Metastock format.  Fortunately, there are about a half dozen open 
> source software packages that will do the full conversion from 
> Metastock files to comma-delimited ASCII files.  However, for a while I 
> had entertained the thought of seeing if this were possible in J.  
> Since my J knowledge isn't all that great, I quickly gave up the idea, 
> though! But I'd still be interested in working bit by bit (pun?) on 
> such a personal project if I knew how to do the 4-byte binary format 
> conversion.  (I think the rest of the binary data is reasonably 
> straightforward to parse--but then again...)  Here are salient excerpts 
> from info found in a couple of the source code projects:  
> 
> 
> SINGLE PRECISION FLOATING POINT:
> 
> /* MS Binary Format                         */
> /* byte order =>    m3 | m2 | m1 | exponent */
> /* m1 is most significant byte => sbbb|bbbb */
> /* m3 is the least significant byte         */
> /*      m = mantissa byte                   */
> /*      s = sign bit                        */
> /*      b = bit                             */
> /*                                          */
> /* IEEE Single Precision Float Format       */
> /*    m3        m2        m1     exponent   */
> /* mmmm|mmmm mmmm|mmmm emmm|mmmm seee|eeee  */
> /*          s = sign bit                    */
> /*          e = exponent bit                */
> /*          m = mantissa bit                */
> /*                                          */
> /* any msbin w/ exponent of zero = zero     */
> /*                                          */
> /* MBF is bias 128 and IEEE is bias 127. ALSO, MBF places   */
> /* the decimal point before the assumed bit, while          */
> /* IEEE places the decimal point after the assumed bit.     */
> 
> 
> DOUBLE PRECISION FLOATING POINT:
> 
> /* MS Binary Format                                           */
> /* byte order =>  m7 | m6 | m5 | m4 | m3 | m2 | m1 | exponent */
> /* m1 is most significant byte => smmm|mmmm                   */
> /* m7 is the least significant byte                           */
> /*      m = mantissa byte                                     */
> /*      s = sign bit                                          */
> /*      b = bit                                               */
> /*                                                            */
> /* IEEE Double Precision Float Format                         */
> /*  byte 8    byte 7    byte 6    byte 5    byte 4  and so on */
> /* seee|eeee eeee|mmmm mmmm|mmmm mmmm|mmmm mmmm|mmmm ...      */
> /*          s = sign bit                                      */
> /*          e = exponent bit                                  */
> /*          m = mantissa bit                                  */
> /*                                                            */
> /* any msbin w/ exponent of zero = zero                       */
> /*                                                            */
> /* MBF is bias 128 and IEEE is bias 1023. ALSO, MBF places    */
> /* the decimal point before the assumed bit, while            */
> /* IEEE places the decimal point after the assumed bit.       */
> /*                                                            */
> /* IEEE has a half byte less for its mantissa.  If the msbin  */
> /* number has anything in this last half byte, then there is  */
> /* an overflow.                                               */
> 
> 
> I included the double precision info for the sake of completeness, but 
> it's not part of the Metastock format, so the double precision 
> conversion is not necessary (though it may be an interesting challenge--
> you never know what kind of data is lurking out there!).  
> 
> Thanks in advance for any conversion code you or someone else can 
> provide!  
> 
> Harvey
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to