[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Getting floating point numbers from binary files



On Mon, Aug 31, 1998 at 09:46:54PM -0500, Christopher F. Blanford wrote:
} 
} Hello all -
} 
} I'm trying to convert binary files from a pre-MS-DOS computer (it even has
} 8 inch floppies) into comma-separated ASCII values. In these files are
} 32-bit real numbers (in IEEE format, i.e., 1 bit sign, 8 bit exponent, 23
} bit remainder) as well as ASCII values and integer values. MacPerl seemed
} suited for this task, but I can't figure out how to get the program to
} read in the bytes as numbers:
} 
} open(FILE,$filename);
} read(FILE,$byteone,1);
} read(FILE,$bytetwo,1);
} read(FILE,$bytethree,1);
} read(FILE,$bytefour,1);
} ...some data manipulation ...
} print $floatingpointequivalent;
} close(FILE);
} 
} For example, if the byte sequence is 43 4E 56 41 it'll give me "CNVB"
} rather than the numerical values. Can someone tell me how I can force it
} to give me the integer values, or better yet, read in a four-byte sequence
} and convert it directly into floating-point.

Read the documentation for pack().  If it works, it'll be the fastest
way. You also have access a full set of C-like bit twiddling
operations, so if, in the end, you have to mask out each bit and add
the individual values up, you can.  But beware that the data might be
little endian (least significant byte first) while MacOS, I think,
runs big endian.  So you might have to do some byte swapping before
you even start.

} 
} Thanks.
} 
} Chris
} 
} - -----------------------------------------------------
} Christopher F. Blanford   V: 612/626-8036
} 180 Kolthoff Hall         F: 612/626-7541
} 207 Pleasant St SE        E: blanf001@tc.umn.edu
} Minneapolis MN 55455      W: http://umn.edu/~blanf001
} - -----------------------------------------------------

----
Paul Schinder
schinder@pobox.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch