From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,4e5ff08a0f67018 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1993-10-08 18:25:45 PST Newsgroups: comp.sys.dec Path: gmd.de!xlink.net!howland.reston.ans.net!spool.mu.edu!agate!headwall.Stanford.EDU!unixhub!slacvx.slac.stanford.edu!fairfield From: fairfield@slacvx.slac.stanford.edu Subject: Re: "byte sex" or "endian" conversion program Message-ID: <1993Oct8.174921.1@slacvx.slac.stanford.edu> Sender: news@unixhub.SLAC.Stanford.EDU Organization: Stanford Linear Accelerator Center References: <1993Oct2.212547.17237@syma.sussex.ac.uk> <28pio0$sgh@jac.nuo.dec.com> <1993Oct8.203318.18135@vpnet.chi.il.us> Date: Sat, 9 Oct 1993 01:49:21 GMT In article <1993Oct8.203318.18135@vpnet.chi.il.us>, kferg@vpnet.chi.il.us (Kevin Ferguson) writes: > In article <28pio0$sgh@jac.nuo.dec.com>, > Steve Lionel wrote: > > [...snip...] >> >>If you're dealing with converting floating-point data between a >>big-endian IEEE system and VAX, you'll need to swap the byte order of >>integers and do a big-endian-IEEE-to-VAX floating conversion. > > [...snip...] > > I have a question regarding the IEEE-to-VAX F_floating point conversion. > > I was recently presented with a pair of routines that > supposedly performed this conversion in each direction. The > amazing thing was (to me anyway) that they obtained the VAX > float format by swapping bytes as you indicated and then > just multiplying by 4. > > I was under the inpression that, due to the different > normalized forms of both the exponent and mantissa, the > conversion was more involved than that. > > If memory serves me right (I don't have a copy of IEEE-754), > IEEE format uses an excess-127 form for its exponent and represents > the most-significant fraction bit. The VAX F_floating point uses > an excess-128 form and the most-significant fraction bit is > implicitly assumed. > > Am I missing something here? Nope, you've got it right. Actually it's quite easy to see. After swapping the bytes (well words) of a VAX F_float, it looks very much like an IEEE single: sign-bit in the left-most position, followed by 8 bits of exponent, followed by 23 bits of mantissa. IEEE chose to use the 8-bits of mantissa differently from the VAX: they chose to use an approximately symmetric range of minimum to maximum values (1.7*10**-38 to 1.7*10**38 as compared to 0.29*10**-38 to 1.7*10*38), and they can do de-normalized numbers, NaN's and Inf's, etc., with the bit patterns that are "left over" compared to the VAX format. The two important points are: 1) if you take the 8-bit IEEE exponent and interpret it as excess-127 instead of excess-128, you get one factor of two; and 2) if you take the normalization of IEEE: 1.bbbbbbbbbbbbbbbbbbbbbbb and compare to the VAX normalization: 0.1bbbbbbbbbbbbbbbbbbbbbbb you get a second factor of two. Result: a simple factor of 4 between the two representations...at least for normalized values within the common range of both representations. BTW, I'll bet is faster to simply add or subtract 2 from the exponent field than it is to do a floating multiply-by-4, although you do have to do bit-field manipulations... -Ken -- Dr. Kenneth H. Fairfield | Internet: Fairfield@Slac.Stanford.Edu SLAC, P.O.Box 4349, MS 98 | DECnet: 45537::FAIRFIELD (45537=SLACVX) Stanford, CA 94309 | FAX: (415) 926-4335 ---------------------------------------------------------------------------- These opinions are mine, not SLAC's, Stanford's, nor the DOE's...