From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 115914,eb58654c5683eea0 X-Google-Attributes: gid115914,public X-Google-Thread: 10cebf,eb58654c5683eea0 X-Google-Attributes: gid10cebf,public X-Google-Thread: 1164f8,eb58654c5683eea0 X-Google-Attributes: gid1164f8,public From: Steve Atkins Subject: Re: VAX D-Float format Date: 1997/10/30 Message-ID: <3458B45F.167E@blighty.com>#1/1 X-Deja-AN: 286840955 References: <34575f82.182344367@serve.installshield.com> Organization: Blighty Design Newsgroups: comp.sys.dec,comp.sys.dec.micro,comp.arch.arithmetic Chieh Cheng wrote: > > I am trying to decode and decipher Intergraph Microstation's Design > file format. It uses the VAX D-Float format. Although it is also 64 > bit long, it is somewhat different from the IEEE double float format. > The format is as follows: > > bit 15: sign > bit 14 - 7: Exponent > bit 6 - 0: Exponent > > bit 16 to 63 is the fraction. I assume it is one fraction, however, > the diagram in the book divided it into three equal parts. Like the > exponent shown above. > > Can someone help me with this format? How can I convert this binary > data to a double float? Ugly, ugly, ugly untested code. This should all be done with structures. This is a really good example as to how not to write bit twiddling code. -------------- uint16 *A; // pointer to float_d uint64 frac; // fraction uint64 s; // sign uint64 exp; // exponent uint64 tfloat; // IEEE double format number double result; s = (*A) >> 15; exp = ((*A) >> 7) & 0xff; frac = ((*A++) & 0x7f) << 16; frac = (frac | (*A++)) << 16; frac = (frac | (*A++)) << 16; frac |= (*A++); tfloat = s << 63; // exp is excess128 for d_floats and excess1023 for t_floats tfloat |= (exp + 1023 - 128) << 48; // You lose three bits of precision tfloat |= frac >> 3; result = *(double*)(&tfloat); -------------- Use at your own risk. -- -- Steve Atkins -- steve@blighty.com -- 'Play that funky music....'