Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: IBM (Intel) Real Numbers Message-ID: <12194@dartvax.Dartmouth.EDU> Date: 13 Feb 89 15:30:58 GMT References: <14486@cup.portal.com> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 50 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <14486@cup.portal.com> Greg_Mark_Finnegan@cup.portal.com writes: > >Has anyone ever tried to read a data file from an IBM PC >that consisted of REAL (in the Pascal sense) numbers. It >only took me a day to remember that byte order is swapped >for INTEGERS, but the same logic (just swapping bytes) >does not work for reals. > >Any help or code would be appreciated. The 8087 "short real" data type is a 32-bit quantity, wherein bits 0 through 22 are the significand, bits 23 through 30 are an exponent with bias 127, and bit 31 is the sign bit. Bit numbering is from lowest to highest address in memory. The integer bit of the significand is implicit in both short and long reals. ------------------------------------------------------------------ |S| EXPONENT | SIGNIFICAND | ------------------------------------------------------------------ 3 2 0 1 3 ^ ^ |- high address low address-| ---- --- I'm not sure, but I believe that the SANE short real data type is the same, but with bit-ordering reversed. (The sign bit is at the lowest address within the real, and the lsb of the significand is at the highest address.) When you transfer the data from the PC to the Mac, if your file transfer is of a type which preserves character values, then it would seem that moving bytes around should work. Try the following scheme, where bytes are numbered from 0 to 3: IBM Mac --- --- 0 3 1 2 2 1 3 0 You should also get both a SANE manual and an 8087 manual, to make sure you are handling special cases (i.e. NAN values) correctly. If at all possible, arrange to get a dump of part of the file's contents in ASCII format on both the IBM and the Mac, to make sure you are doing the right thing... Earle R. Horton. 23 Fletcher Circle, Hanover, NH 03755--Graduate student. He who puts his hand to the plow and looks back is not fit for the kingdom of winners. In any case, 'BACK' doesn't work.