From: fairfield@slacvx.slac.stanford.edu
Subject: Re: "byte sex" or "endian" conversion program
Date: Sat, 9 Oct 1993 01:49:21 GMT [thread overview]
Message-ID: <1993Oct8.174921.1@slacvx.slac.stanford.edu> (raw)
In-Reply-To: 1993Oct8.203318.18135@vpnet.chi.il.us
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 <lionel@quark.enet.dec.com> 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. <jaw hits floor>
>
> 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...
prev parent reply other threads:[~1993-10-09 1:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-10-02 21:25 "byte sex" or "endian" conversion program Greg Sandell
1993-10-03 14:56 ` Charles M Richmond
1993-10-04 4:33 ` Thad P Floryan
1993-10-04 16:24 ` Steve Lionel
1993-10-08 20:33 ` Kevin Ferguson
1993-10-09 1:49 ` fairfield [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox