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.[1][2][3][4][5][6][7]

There are two main versions of the format. The original version was designed for memory-constrained systems and stored numbers in 32-bits (4 bytes), with a 23-bit mantissa, 1-bit sign, and an 8-bit exponent. Extended (12k) BASIC included a double-precision type with 64-bits.

During the port to the MOS 6502, computers were beginning to ship with more memory, so a version was offered with the original 32-bit format, or an expanded 40-bit (5-byte) format. The 40-bit format was used by most home computers of the 1970s and 1980s. These two versions are sometimes known as "6-digit" and "9-digit", respectively.[8]

QuickBASIC, prior to version 4, reintroduced the double-precision format using a 55-bit mantissa in a 64-bit (8 bytes) double-precision format. MBF was abandoned during the move to QuickBASIC 4, which instead used the standard IEEE 754 format, introduced a few years earlier.


Bill Gates and Paul Allen were working on Altair BASIC in 1975. They were developing the software at Harvard University on a DEC PDP-10 running their Altair emulator.[9] One thing they lacked was code to handle floating-point numbers, required to support calculations with very big and very small numbers,[9] which would be particularly useful for science and engineering.[10][11] One of the proposed uses of the Altair was as a scientific calculator.[12]

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

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.[15][16] A comment in the source credits Davidoff as the writer of Altair BASIC's math package.[15][16]

Altair BASIC took off, and soon most early home computers ran some form of Microsoft BASIC.[17][18] 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 to 40 bits.[19] 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).[19] 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.[20][21][22] Microsoft used the same floating-point formats in their implementation of Fortran[23] and for their macro assembler MASM,[24] although their spreadsheet Multiplan[25][26] and their COBOL implementation used binary-coded decimal (BCD) floating point.[27] 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.[28][29][30][31][32][33]

IEEE 754

As early as in 1976, Intel was starting the development of a floating-point coprocessor.[34][35] Intel hoped to be able to sell a chip containing good implementations of all the operations found in the widely varying maths software libraries.[34][36]

John Palmer, who managed the project, contacted William Kahan of the University of California, 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.[34]

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.[34][35][36][37] VAX's floating-point formats differed from MBF only in that it had the sign in the most significant bit.[38][39]

It turned out that an 8-bit exponent was not wide enough for some operations desired for double-precision numbers, e.g. to store the product of two 32-bit numbers.[1] Both Kahan's proposal and a counter-proposal by DEC therefore used 11 bits, like the time-tested 60-bit floating-point format of the CDC 6600 from 1965.[35][37][40] 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;[37][41][42] and a better balanced exponent bias, which can help avoid overflow and underflow when taking the reciprocal of a number.[43][44]

In 1980 the Intel 8087 chip was already released,[45] 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.[35][37][46]

By the time QuickBASIC 4.00 was released, the IEEE 754 standard had become widely adoptedfor example, it was incorporated into Intel's 387 coprocessor and every x86 processor from the 486 on. QuickBASIC versions 4.0 and 4.5 use IEEE 754 floating-point variables by default, but (at least in version 4.5) there is a command-line option /MBF for the IDE and the compiler that switches from IEEE to MBF floating-point numbers, to support earlier-written programs that rely on details of the MBF data formats. Visual Basic also uses the IEEE 754 format instead of MBF.

Technical details

MBF numbers consist of an 8-bit base-2 exponent with a bias of 128, so that exponents −127…−1 are represented by x = 1…127 (01h…7Fh), exponents 0…127 are represented by x = 128…255 (80h…FFh), with a special case for x = 0 (00h) representing the whole number being zero, a sign bit (positive mantissa: s = 0; negative mantissa: s = 1) and a 23-,[19] 31-[19] or 55-bit mantissa of the significand. There is always a 1-bit implied to the left of the explicit mantissa, and the radix point is located before this 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.[1][3][47][48] Unlike IEEE floating point, MBF doesn't support denormal numbers, infinities or NaNs.[49]

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

8 bits,
bit 31–24
1 bit,
bit 23
23 bits,
bit 22–0

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

8 bits,
bit 39–32
1 bit,
bit 31
31 bits,
bit 30–0

MBF double-precision format (64 bits):

8 bits,
bit 63–56
1 bit,
bit 55
55 bits,
bit 54–0


32-bit format: 84h, 20h, 00h, 00h
40-bit format: 84h, 20h, 00h, 00h, 00h
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)
32-bit format: 80h, 00h, 00h, 00h
40-bit format: 80h, 00h, 00h, 00h, 00h
32-bit format: 7Fh, 00h, 00h, 00h
40-bit format: 7Fh, 00h, 00h, 00h, 00h
32-bit format: 80h, 80h, 00h, 00h
40-bit format: 80h, 80h, 00h, 00h, 00h
32-bit format: 80h, 35h, 04h, F3h
40-bit format: 80h, 35h, 04h, F3h, 34h
32-bit format: 81h, 35h, 04h, F3h
40-bit format: 81h, 35h, 04h, F3h, 34h
32-bit format: 80h, 31h, 72h, 18h
40-bit format: 80h, 31h, 72h, 17h, F8h
32-bit format: 81h, 38h, AAh, 3Bh
40-bit format: 81h, 38h, AAh, 3Bh, 29h
32-bit format: 81h, 49h, 0Fh, DBh
40-bit format: 81h, 49h, 0Fh, DAh, A2h
32-bit format: 83h, 49h, 0Fh, DBh
40-bit format: 83h, 49h, 0Fh, DAh, A2h

See also


  1. "IEEE vs. Microsoft Binary Format; Rounding Issues (Complete)". Microsoft Support. 2006-11-21. Retrieved 2010-02-24.
  2. "(Complete) Tutorial to Understand IEEE Floating-Point Errors". Retrieved 2016-06-02.
  3. "Article: Floating Point Numbers". Retrieved 2016-06-02. Read with care. The second reference could be mistaken to say that QB 4.0 could use MBF internally, but it only uses IEEE. It just has a few conversion functions to convert IEEE floating point numbers to strings containing MBF data, e.g. MKDMBF$ in addition to MKD$ which just copies the bytes of the IEEE value to a string.
  4. "The MASM 6.1 documentation notes that 5.1 was the last MASM version to support MBF" (PDF). Retrieved 2016-06-02.
  5. GW-BASIC User's Manual, Appendix D.3 USR Function Calls
  6. BASIC Second edition (May 1982), IBM: Appendix C-15 (This is the BASICA manual.)
  7. "ROM Routes (Integer Math)". Retrieved 2016-06-02.
  8. Steil, Michael (2008-10-20). "Create your own Version of Microsoft BASIC for 6502".
  9. Ireland, Corydon. "Dawn of a revolution | Harvard Gazette". Retrieved 2016-05-30.
  10. Rall, L. B. (1987). "An introduction to the scientific computing language Pascal-SC". Computers. 14: 53–69. doi:10.1016/0898-1221(87)90181-7.
  11. Leung, K. Ming. "Floating-Point Numbers in Digital Computers" (PDF). Retrieved 2016-06-02.
  12. Becraft, Michael B. (2014-08-26). Bill Gates: A Biography. ISBN 978-1-44083014-3. Retrieved 2016-05-30.
  13. "Altair BASIC 3.2 (4K Edition)". Retrieved 2016-05-30.
  14. "Microsoft Altair BASIC legend talks about Linux, CPRM and that very frightening photo". Retrieved 2016-05-30.
  15. "Raiders of the Lost Altair BASIC Source Code". Retrieved 2016-05-30.
  16. "Quest for the Holy Source - Ian's trip to Harvard". Archived from the original on 2002-01-02. Retrieved 2016-05-30.
  17. "Important computer inventors". Retrieved 2016-05-30.
  18. "Basic 7.0 for Windows". Retrieved 2016-05-30.
  19. Steil, Michael (2008-10-20). "Create your own Version of Microsoft BASIC for 6502". Archived from the original on 2016-05-30. Retrieved 2016-05-30.
  20. "Radio Shack Hardware Manual: Level II BASIC Reference Manual 1st Ed. (1978)(Radio Shack): Free Download & Streaming: Internet Archive". Retrieved 2016-05-30.
  21. "Level II Basic" (PDF). Retrieved 2016-06-02.
  22. "BASIC-80 (MBASIC) Reference Manual" (PDF). Retrieved 2016-05-30.
  23. "(page 45 and 55)" (PDF). Retrieved 2016-05-30.
  24. Pätzold, M., ed. (April 1993). "Zettelsammlung MS-DOS und AT" (in German). Gruppe Datenverarbeitung am MPI für Strömungsforschung Göttingen, Max-Planck-Institut. Archived from the original on 2005-02-20. Retrieved 2015-10-07.
  25. "Tandy 200 Multiplan Manual" (PDF). Retrieved 2016-06-02.
  26. Microsoft C Pcode Specifications, page 13; Multiplan wasn't compiled to machine code, but to a kind of byte-code which was run by an interpreter, in order to make Multiplan portable across the widely varying hardware of the time. This byte-code distinguished between the machine-specific floating point format to calculate on, and an external (standard) format, which was binary coded decimal (BCD). The PACK and UNPACK instructions converted between the two.
  27. "(page 26 = 32 in the PDF)" (PDF). Retrieved 2016-05-30.
  28. Lee, Patrick Y. "QWK Mail Packet File Layout" (TXT). Retrieved 2016-06-02.
  29. "This document describes the abandoned CompuTrac data format, which until recently was actively used by Equis' MetaStock charting software". Archived from the original (TXT) on 2016-03-05. Retrieved 2016-06-02.
  30. "Converting Microsoft Binary Format to IEEE format Using VB 6". 2016-05-04. Retrieved 2016-05-30.
  31. "Help !Anybody know how to convert old M/S MBF value from Qbasic to VB6 - Visual Basic(Microsoft): Version 5 & 6". Tek-Tips. Retrieved 2016-05-30.
  32. GL88. "Reading Binary Format (QBasic) with C#". Retrieved 2016-05-30.
  33. "Rmetrics - Reading MetaStock data format in R". 2013-09-30. Retrieved 2016-05-30.
  34. "Intel and Floating-Point - Updating One of the Industry's Most Successful Standards" (PDF). Archived from the original (PDF) on 2016-03-04. Retrieved 2016-05-30. (11 pages)
  35. "An Interview with the Old Man of Floating-Point". 1998-02-20. Retrieved 2016-05-30.
  36. Woehr, Jack (1997-11-01). "A Conversation with William Kahan | Dr. Dobb's". Retrieved 2016-05-30.
  37. "IEEE 754: An Interview with William Kahan" (PDF). Retrieved 2016-06-02.
  38. "The VAX-11/780 did not implement the "G" format yet. Although this is not directly apparent from the tables because the structures have been cut up in two-byte words, the byte order is actually the same as on modern CPUs. There isn't enough room in the exponent range for NaNs, Infinity, infinities or denormals". Retrieved 2016-06-02.
  39. "VAX11 780" (PDF). Retrieved 2016-06-02.
  40. Thornton, J. E. "Design of a Computer: The Control Data 6600" (PDF). Retrieved 2016-06-02.
  41. Kahan, William Morton. "Why do we need a floating-point arithmetic standard?" (PDF). Retrieved 2016-06-02.
  42. Kahan, William Morton; Darcy, Joseph D. "How Java's Floating-Point Hurts Everyone Everywhere" (PDF). Retrieved 2016-06-02.
  43. Turner, Peter R. (2013-12-21). Numerical Analysis and Parallel Processing: Lectures given at The Lancaster ... ISBN 978-3-66239812-8. Retrieved 2016-05-30.
  44. "Names for Standardized Floating-Point Formats" (PDF). Retrieved 2016-06-02.
  45. "Molecular Expressions: Science, Optics & You - Olympus MIC-D: Integrated Circuit Gallery - Intel 8087 Math Coprocessor". Retrieved 2016-05-30.
  46. Kahan, William Morton. "IEEE Standard 754 for Binary Floating-Point Arithmetic" (PDF). Retrieved 2016-06-02.
  47. Borland staff (1998-07-02) [1994-03-10]. "Converting between Microsoft Binary and IEEE formats". Technical Information Database (TI1431C.txt). Embarcadero USA (originally: Borland). 1400. Archived from the original on 2019-02-20. Retrieved 2016-05-30.
  48. "Google Groups". Retrieved 2016-06-02.
  49. "julian m bucknall >> Understanding single precision MBF". Retrieved 2016-05-30.
  • Microsoft provides a dynamic link library for 16-bit Visual Basic containing functions to convert between MBF data and IEEE 754.
    • This library wraps the MBF conversion functions in the 16-bit Visual C(++) CRT.
    • These conversion functions will round an IEEE double precision number like ¾ ⋅ 2−128 to zero rather than to 2−128.
    • They don't support denormals at all: the IEEE or MBF single precision number 2−128 will be converted to zero even though it is representable in either format.
    • This library is only intended for use with Visual Basic; C(++) programs are expected to call the CRT functions directly.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.