Harman Patil (Editor)

Microsoft Binary Format

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Microsoft Binary Format

In computing, Microsoft Binary Format (MBF) was a format for floating point numbers used in Microsoft's BASIC language products including MBASIC, GW-BASIC and QuickBasic prior to version 4.00.

Contents

History

In 1975, Bill Gates and Paul Allen were working on Altair BASIC, which they were developing at Harvard University on a PDP-10 running their Altair emulator. One thing still missing was code to handle floating point numbers, needed to support calculations with very big and very small numbers, which would be particularly useful for science and engineering. One of the proposed uses of the Altair was as a scientific calculator.

At a dinner at Currier House, an undergraduate residential house at Harvard, Gates and Allen complained to their dinner companions about having to write this code. One of them, Monte Davidoff, told them he had written floating point routines before and convinced Gates and Allen that he was capable of writing the Altair BASIC floating point code. At the time there was no standard for floating point numbers, so Davidoff had to come up with his own. He decided 32 bits would allow enough range and precision. When Allen had to demonstrate it to MITS, it was the first time it ran on an actual Altair. But it worked and when he entered ‘PRINT 2+2’, Davidoff's adding routine gave the right answer.

The source code for Altair BASIC was thought to have been lost to history, but resurfaced in 2000. It had been sitting behind Gates's former tutor and dean Harry Lewis's file cabinet, who rediscovered it. A comment in the source credits Davidoff as the writer of Altair BASIC's math package.

Altair BASIC took off and soon most early home computers ran some form of Microsoft BASIC. The BASIC port for the 6502 CPU, such as used in the Commodore PET, took up more space due to the lower code density of the 6502. Because of this it would likely not fit in a single ROM chip together with the machine-specific input and output code. Since an extra chip was necessary, extra space was available and this was used in part to extend the floating point format from 32 bit to 40 bit. This extended format was not only provided by Commodore BASIC 1 & 2, but was also supported by AppleSoft BASIC I & II since version 1.1 (1977), KIM-1 BASIC since version 1.1a (1977), and MicroTAN BASIC since version 2b (1980). Not long afterwards the Z80 ports, such as Level II BASIC for the TRS-80 (1978), introduced the 64 bit, double precision format as a separate data type from 32 bit, single precision. Microsoft used the same floating point formats in their implementation of Fortran and for their macro assembler MASM, although their spreadsheet Multiplan and their COBOL implementation used binary coded decimal (BCD) floating point. Even so, for a while MBF became the de facto floating point format on home computers, to the point where people still occasionally encounter legacy files and file formats using it.

As early as in 1976, Intel was starting the development of a floating point coprocessor. Intel hoped to be able to sell a chip containing good implementations of all the operations found in the widely varying maths software libraries. John Palmer, who managed the project, contacted William Kahan, who suggested that Intel use the floating point of Digital Equipment Corporation's (DEC) VAX. The first VAX, the VAX-11/780 had just come out in late 1977 and its floating point was highly regarded. However, seeking to market their chip to the broadest possible market, Intel wanted the best floating point possible and Kahan went on to draw up specifications. When rumours of Intel's new chip reached its competitors they started a standardization effort, called IEEE 754, to prevent Intel from gaining too much ground. Kahan got Palmer's permission to participate; he was allowed to explain Intel's design decisions and their underlying reasoning, but not anything related to Intel's implementation architecture. VAX's floating point formats differed from MBF only in that it had the sign in the most significant bit. It turned out that for double precision numbers, an 8 bit exponent isn't wide enough for some wanted operations, e.g. to store the product of two 32-bit numbers.

Both Kahan's proposal and a counter-proposal by DEC therefore used 11 bits, like the time-tested 60 bits floating point format of the CDC 6600 from 1965. Kahan's proposal also provided for infinities, which are useful when dealing with division-by-zero conditions, not-a-number values, which are useful when dealing with invalid operations, denormal numbers, which help mitigate problems caused by underflow, and a better balanced exponent bias, which can help avoid overflow and underflow when taking the reciprocal of a number. In 1980 the Intel 8087 chip was already released, but DEC remained opposed, to denormal numbers in particular, because of performance concerns and since it would give DEC a competitive advantage to standardise on DEC's format. The next year DEC had a study done in order to demonstrate that gradual underflow was a bad idea, but the study concluded the opposite and DEC gave in. In 1985 the standard was ratified, but it had already become the de facto standard a year earlier, implemented by many manufacturers.

By the time QuickBASIC 4.00 was released, the IEEE 754 standard had become widely adopted - for example, it was incorporated into Intel's 387 coprocessor and every x86 processor from the 486 on. Visual Basic also uses the IEEE 754 format instead of MBF.

Technical details

MBF numbers consist of an eight bit base-2 exponent with bias 129 (value 0: x=0 (00h); exponents -128..-1: x=1..128 (01h..80h), exponents 0..126: x=129..255 (81h..FFh)), a sign bit (positive mantissa: s=0; negative mantissa: s=1) and a 23, 31 or 55 bit fractional part of the significand. The decimal point is located before the assumed bit. The MBF double precision format provides less scale than the IEEE 754 format, and although the format itself provides almost one extra decimal digit of precision, in practice the stored values are less accurate because IEEE calculations use 80-bit intermediate results and MBF doesn't. Unlike IEEE floating point, MBF doesn't support denormal numbers, infinities or NaNs.

MBF single-precision format (32 bits, "6-digit BASIC"):

MBF extended-precision format (40 bits, "9?-digit BASIC"):

MBF double-precision format (64 bits):

Examples

  • "10":
  • 32-bit format: 84h, 20h, 00h, 00h 40-bit format: 84h, 20h, 00h, 00h, 00h
  • "1":
  • 32-bit format: 81h, 00h, 00h, 00h 40-bit format: 81h, 00h, 00h, 00h, 00h
  • "0":
  • 32-bit format: 00h, 00h, 00h, 00h (or 00h, xxh, xxh, xxh) 40-bit format: 00h, 00h, 00h, 00h, 00h (or 00h, xxh, xxh, xxh, xxh)
  • "0.5":
  • 32-bit format: 80h, 00h, 00h, 00h 40-bit format: 80h, 00h, 00h, 00h, 00h
  • "0.25":
  • 32-bit format: 7Fh, 00h, 00h, 00h 40-bit format: 7Fh, 00h, 00h, 00h, 00h
  • "-0.5":
  • 32-bit format: 80h, 80h, 00h, 00h 40-bit format: 80h, 80h, 00h, 00h, 00h
  • "sqrt(0.5)":
  • 32-bit format: 80h, 35h, 04h, F3h 40-bit format: 80h, 35h, 04h, F3h, 34h
  • "sqrt(2)":
  • 32-bit format: 81h, 35h, 04h, F3h 40-bit format: 81h, 35h, 04h, F3h, 34h
  • "ln(2)":
  • 32-bit format: 80h, 31h, 72h, 18h 40-bit format: 80h, 31h, 72h, 17h, F8h
  • "log2(e)":
  • 32-bit format: 81h, 38h, AAh, 3Bh 40-bit format: 81h, 38h, AAh, 3Bh, 29h
  • "pi/2":
  • 32-bit format: 81h, 49h, 0Fh, DBh 40-bit format: 81h, 49h, 0Fh, DAh, A2h
  • "2*pi":
  • 32-bit format: 83h, 49h, 0Fh, DBh 40-bit format: 83h, 49h, 0Fh, DAh, A2h

    References

    Microsoft Binary Format Wikipedia