🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7864

Re: Microsoft Binary Format

#7864
From: Bob Stout
Date: Mon, 21 Aug 1995 22:06
86 lines
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
Technical Details
Message-ID: <Pine.BSD.3.91.950821170512.5980A-100000@Starbase.NeoSoft.COM>
Path: arc1-ca.pugleaf.net!Starbase.NeoSoft.COM!bobstout
References: <41a5ft$hfi@netnews.upenn.edu> <obotherDDo8oz.JIr@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!Starbase.NeoSoft.COM!bobstout
From: Bob Stout <bobstout@neosoft.com>
Newsgroups: comp.os.msdos.programmer,comp.os.msdos.misc,comp.os.ms-windows.programmer,comp.lang.c,comp.lang.pascal
Subject: Re: Microsoft Binary Format
Date: Mon, 21 Aug 1995 17:06:31 -0500
Organization: NeoSoft Internet Services   +1 713 968 5800
Message-ID: <Pine.BSD.3.91.950821170512.5980A-100000@Starbase.NeoSoft.COM>
References: <41a5ft$hfi@netnews.upenn.edu> <obotherDDo8oz.JIr@netcom.com>
NNTP-Posting-Host: starbase.neosoft.com
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
In-Reply-To: <obotherDDo8oz.JIr@netcom.com>