Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Microsoft Binary Format

127 views
Skip to first unread message

Falstaff

unread,
Aug 21, 1995, 3:00:00 AM8/21/95
to
mer...@dolphin.upenn.edu (Fred Charles Merkel) writes:


>I just received a huge chunk of data in "Microsoft Binary Format". The
>data are in four byte words, but they don't seem to correspond to normal
>floats or ints.

>Does anyone know what MBF is or can anyone give me some pointers to finding
>out more?

Aahh, yes, another mickeysoft 'standard'.
From the masm manual:
31..24 exponent
23 sign
22..0 mantissa

The three parts of real numbers are described below
1. Biased exponent (8 bits) in the high-address byte. Bias is 81h
2. Sign bit is 0 for positive 1 for negative
3. All except the first set bit of mantissa in the remainting 7 bits
of the second-highest byte and in the remaining bytes of the variable.

Even MS decided to drop this format, as it is incompatible with anything
you may find in the real world (if MS programmers ever get there...)

Frank
--
------------------------------------------------------------------------
Frank A. Vorstenbosch +31-(70)-355 5241 fals...@xs4all.nl

Fred Charles Merkel

unread,
Aug 21, 1995, 3:00:00 AM8/21/95
to

I just received a huge chunk of data in "Microsoft Binary Format". The
data are in four byte words, but they don't seem to correspond to normal
floats or ints.

Does anyone know what MBF is or can anyone give me some pointers to finding
out more?

Thanks a lot in advance!

Fred Merkel

Bob Stout

unread,
Aug 21, 1995, 3:00:00 AM8/21/95
to
On Mon, 21 Aug 1995, Glen Blankenship wrote:

> Microsoft's C compilers include runtime library functions to convert
> between MBF and IEEE floating-point formats. If you have four-byte
> MBF numbers, the function you need is _fmsbintoieee(). For eight-byte
> double-precision MBF numbers, you'd use _dmsbintoieee().
>
> Borland's compilers don't include these functions in their runtime
> library, but C source to implement these functions can be obtained
> from:
>
> ftp://ftp.borland.com/pub/techinfo/techdocs/language/c++/bcpp/msbin.zip
>
> Note, however, that there's a slight bug in Borland's implementation
> of _fmsbintoieee().

The following, from SNIPPETS, is TTBOMK, correct...

/*** MSBIN conversion routines ***/
/*** public domain by Jeffery Foy ***/

union Converter {
unsigned char uc[10];
unsigned int ui[5];
unsigned long ul[2];
float f[2];
double d[1];
};

/* MSBINToIEEE - Converts an MSBIN floating point number */
/* to IEEE floating point format */
/* */
/* Input: f - floating point number in MSBIN format */
/* Output: Same number in IEEE format */

float MSBINToIEEE(float f)
{
union Converter t;
int sign, exp; /* sign and exponent */

t.f[0] = f;

/* extract the sign & move exponent bias from 0x81 to 0x7f */

sign = t.uc[2] / 0x80;
exp = (t.uc[3] - 0x81 + 0x7f) & 0xff;

/* reassemble them in IEEE 4 byte real number format */

t.ui[1] = (t.ui[1] & 0x7f) | (exp << 7) | (sign << 15);
return t.f[0];
} /* End of MSBINToIEEE */


/* IEEEToMSBIN - Converts an IEEE floating point number */
/* to MSBIN floating point format */
/* */
/* Input: f - floating point number in IEEE format */
/* Output: Same number in MSBIN format */

float IEEEToMSBIN(float f)
{
union Converter t;
int sign, exp; /* sign and exponent */

t.f[0] = f;

/* extract sign & change exponent bias from 0x7f to 0x81 */

sign = t.uc[3] / 0x80;
exp = ((t.ui[1] >> 7) - 0x7f + 0x81) & 0xff;

/* reassemble them in MSBIN format */

t.ui[1] = (t.ui[1] & 0x7f) | (sign << 7) | (exp << 8);
return t.f[0];
} /* End of IEEEToMSBIN */


-------------------------------------------------------------
MicroFirm: Down to the C in chips...
FidoNet 1:106/2000.6
Internet bobs...@neosoft.com
Home of SNIPPETS - Current release:
oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
juge.com:/c/file/c/snip9503.lzh


Glen Blankenship

unread,
Aug 21, 1995, 3:00:00 AM8/21/95
to
[Followups have been trimmed to comp.os.msdos.programmer]

Fred Charles Merkel (mer...@dolphin.upenn.edu) wrote:
> I just received a huge chunk of data in "Microsoft Binary Format". The
> data are in four byte words, but they don't seem to correspond to normal
> floats or ints.
>
> Does anyone know what MBF is or can anyone give me some pointers to finding
> out more?

Microsoft's C compilers include runtime library functions to convert


between MBF and IEEE floating-point formats. If you have four-byte
MBF numbers, the function you need is _fmsbintoieee(). For eight-byte
double-precision MBF numbers, you'd use _dmsbintoieee().

Borland's compilers don't include these functions in their runtime
library, but C source to implement these functions can be obtained
from:

ftp://ftp.borland.com/pub/techinfo/techdocs/language/c++/bcpp/msbin.zip

Note, however, that there's a slight bug in Borland's implementation
of _fmsbintoieee().

The lines:

/* any msbin w/ exponent of zero = zero */
if (msbin[3] == 0) return 0;

...should be changed to:

/* any msbin w/ exponent of zero = zero, and any msbin
w/ exponent < 2 is too small to represent in IEEE format */
if (msbin[3] < 2) return 0;

...otherwise very small numbers will produce erroneous results.

---
Glen Blankenship
obo...@netcom.com


Glen Blankenship

unread,
Aug 22, 1995, 3:00:00 AM8/22/95
to
Bob Stout (bobs...@neosoft.com) wrote:

> The following, from SNIPPETS, is TTBOMK, correct...
>
> /*** MSBIN conversion routines ***/
> /*** public domain by Jeffery Foy ***/

[snip]

No, this is even worse than the Borland routine, since it doesn't even
return zero when the MSBIN exponent is zero. The line:

> exp = (t.uc[3] - 0x81 + 0x7f) & 0xff;

...will produce erroneous results any time the value of t.uc[3] is less
than or equal to 2. It will return incorrect values not only for very
small numbers (like the Borland function), but also for the value 0.

(Note that my correction to the Borland routine used "less than 2" when it
should have used "less than or equal to 2". My apologies for the error.)

In addition, the IEEEtoMSBIN routine has no provision for reporting overflow
if the IEEE number is too large to fit in the MSBIN format.

(The MS and Borland routines take pointers to both the number to be
converted and a float to hold the result, and indicate success or overflow
via the value of the function return. The IEEEtoMSBIN routine simply
returns an incorrect result in the event of overflow.)

---
Glen Blankenship
obo...@netcom.com


Bob Stout

unread,
Aug 22, 1995, 3:00:00 AM8/22/95
to
On Tue, 22 Aug 1995, Glen Blankenship wrote:

> > The following, from SNIPPETS, is TTBOMK, correct...
> >
> > /*** MSBIN conversion routines ***/
> > /*** public domain by Jeffery Foy ***/
>
> [snip]
>
> No, this is even worse than the Borland routine, since it doesn't even
> return zero when the MSBIN exponent is zero.

Thanks for the feedback - I'll try to get it fixed it for the next release.

0 new messages