Thread View: comp.os.msdos.programmer
6 messages
6 total messages
Started by Fred Charles Merkel
Mon, 21 Aug 1995 14:33
Microsoft Binary Format
Author: Fred Charles Merkel
Date: Mon, 21 Aug 1995 14:33
Date: Mon, 21 Aug 1995 14:33
11 lines
741 bytes
741 bytes
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
Re: Microsoft Binary Format
Author: Falstaff
Date: Mon, 21 Aug 1995 16:36
Date: Mon, 21 Aug 1995 16:36
29 lines
1564 bytes
1564 bytes
merkel@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 falstaff@xs4all.nl
Re: Microsoft Binary Format
Author: Glen Blankenship
Date: Mon, 21 Aug 1995 17:31
Date: Mon, 21 Aug 1995 17:31
40 lines
1870 bytes
1870 bytes
[Followups have been trimmed to comp.os.msdos.programmer]
Fred Charles Merkel (merkel@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
obother@netcom.com
Re: Microsoft Binary Format
Author: Bob Stout
Date: Mon, 21 Aug 1995 22:06
Date: Mon, 21 Aug 1995 22:06
86 lines
3393 bytes
3393 bytes
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 bobstout@neosoft.com
Home of SNIPPETS - Current release:
oak.oakland.edu:/SimTel/msdos/c/snip9503.zip
juge.com:/c/file/c/snip9503.lzh
Re: Microsoft Binary Format
Author: Glen Blankenship
Date: Tue, 22 Aug 1995 20:08
Date: Tue, 22 Aug 1995 20:08
32 lines
1889 bytes
1889 bytes
Bob Stout (bobstout@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 obother@netcom.com
Re: Microsoft Binary Format
Author: Bob Stout
Date: Tue, 22 Aug 1995 21:04
Date: Tue, 22 Aug 1995 21:04
21 lines
1420 bytes
1420 bytes
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. ------------------------------------------------------------- MicroFirm: Down to the C in chips... FidoNet 1:106/2000.6 Internet bobstout@neosoft.com Home of SNIPPETS - Current release: oak.oakland.edu:/SimTel/msdos/c/snip9503.zip juge.com:/c/file/c/snip9503.lzh
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads