From Surf Wiki (app.surf) — the open knowledge base
Microsoft Binary Format
Floating-point number format by Microsoft
Floating-point number format by Microsoft
In computing, Microsoft Binary Format (MBF) is a format for floating-point numbers which was used in Microsoft's BASIC languages, including MBASIC, GW-BASIC and QuickBASIC prior to version 4.00.
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 period when it was being ported from the Intel 8080 platform to the MOS 6502 processor, computers were beginning to ship with more memory as a standard feature. This version was offered with the original 32-bit format or an optional 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.
On PCs with x86 processor, QuickBASIC, prior to version 4, reintroduced the double-precision format using a 55-bit mantissa in a 64-bit (8-byte) format. MBF was abandoned during the move to QuickBASIC 4, which used the standard IEEE 754 format, introduced a few years earlier.
History
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. One thing they lacked was code to handle floating-point numbers, required 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 that they had to write this code 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. 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. 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 correct answer.
A copy of the source code for Altair BASIC resurfaced in 1999. In the late 1970s, Gates's former tutor and dean Harry Lewis had found it behind some furniture in an office in Aiden, and put it in a file cabinet. After more or less forgetting about its existence for a long time, Lewis eventually came up with the idea of displaying the listing in the lobby. Instead, it was decided on preserving the original listing and producing several copies for display and preservation, after librarian and conservator Janice Merrill-Oldham pointed out its importance. 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 to 40 bits. 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.
In a parallel development, Intel had started the development of a floating-point coprocessor in 1976. William Morton Kahan, as a consultant to Intel, 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. VAX's floating-point formats differed from MBF only in that it had the sign in the most significant bit. However, seeking to market their chip to the broadest possible market, Kahan was asked 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. As 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, Intel's proposal and a counter-proposal from DEC used 11 bits, like the time-tested 60-bit 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 could help avoid overflow and underflow when taking the reciprocal of a number.
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. 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 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.
{{anchor|32-bit MBF|40-bit MBF|64-bit MBF}}Technical details
MBF numbers consist of an 8-bit base-2 exponent, a sign bit (positive mantissa: s = 0; negative mantissa: s = 1) and a 23-, 31- 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 exponent is encoded with a bias of , so that exponents are represented by x = , exponents are represented by x = , with a special case for x = 0 (00h) representing the whole number being zero.
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"):
| Exponent | Sign | Significand | Bit 31...24 |
|---|---|---|---|
| (8 bit) | Bit 23 | ||
| (1 bit) | Bit 22...0 | ||
| (23 bit) | |||
| xxxxxxxx | s | mmmmmmm mmmmmmmm mmmmmmmm |
MBF extended-precision format (40 bits, "9-digit BASIC"):
| Exponent | Sign | Significand | Bit 39...32 |
|---|---|---|---|
| (8 bit) | Bit 31 | ||
| (1 bit) | Bit 30...0 | ||
| (31 bit) | |||
| xxxxxxxx | s | mmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
MBF double-precision format (64 bits):
| Exponent | Sign | Significand | Bit 63...56 |
|---|---|---|---|
| (8 bit) | Bit 55 | ||
| (1 bit) | Bit 54...0 | ||
| (55 bit) | |||
| xxxxxxxx | |||
| s | |||
| mmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm | |||
| mmmmmmmm mmmmmmmm mmmmmmmm |
Examples
| Examples | 32-bit format | 40-bit format | References
; these values are /1000 of what the labels say CON_99999999_9: : 32-bit format: 91h, 43h, 4Fh, F8h : 40-bit format: 9Bh, 3Eh, BCh, 1Fh, FDh
CON_999999999: |= 94h, 74h, 23h, F7h |= 9Eh, 6Eh, 6Bh, 27h, FEh ; alternative values |= 9Eh, 6Eh, 6Bh, 27h, FDh ; alternative values
CON_BILLION: |= 94h, 74h, 24h, 00h |= 9Eh, 6Eh, 6Bh, 28h, 00h
References
References
- (2006-11-21). "IEEE vs. Microsoft Binary Format; Rounding Issues (Complete)". [[Microsoft]].
- (2010-04-21). "Convert pre-IEEE-754 C++ floating-point numbers to/from C#".
- (2013-09-20). "Dawn of a revolution". news.harvard.edu.
- (2001-05-13). "Raiders of the Lost Altair BASIC Source Code - They came, they saw … they disassembled".
- (2000-05-08). "Quest for the Holy Source - Ian's trip to Harvard".
- (2008-10-20). "Create your own Version of Microsoft BASIC for 6502". pagetable.com.
- (2008-10-20). "msbasic/float.s". MIST64.
- (2008-10-20). "msbasic/trig.s". MIST64.
- Borland staff. (1998-07-02). "Converting between Microsoft Binary and IEEE formats". [[Embarcadero USA]] / [[Inprise]] (originally: [[Borland]]).
- (2005-08-16). "(Complete) Tutorial to Understand IEEE Floating-Point Errors". [[Microsoft]].
- "The MASM 6.1 documentation notes that 5.1 was the last MASM version to support MBF".
- GW-BASIC User's Manual, Appendix D.3 USR Function Calls.
- BASIC Second edition (May 1982), IBM: Appendix C-15 (NB. This is the BASICA manual).
- "ROM Routes (Integer Math)".
- (1987). "An introduction to the scientific computing language Pascal-SC". [[Pergamon Journals Ltd]].
- (2005-02-03). "Floating-Point Numbers in Digital Computers".
- (2014-08-26). "Bill Gates: A Biography". Abc-Clio.
- (2014). "The Math Package".
- (2001-05-11). "Microsoft Altair BASIC legend talks about Linux, CPRM and that very frightening photo - A very rare interview with Monte Davidoff".
- (2020-07-18). "Great people personally responsible for advancing the art of early computers".
- "Basic 7.0 for Windows".
- (1978). "Radio Shack Hardware Manual: Level II BASIC Reference Manual". [[Radio Shack]].
- (1979). "Level II BASIC Reference Manual". [[Radio Shack]].
- "BASIC-80 (MBASIC) Reference Manual".
- (November 1980). "Microsoft FORTRAN-80 Version 3.4 Users Manual".
- (April 1993). "Zettelsammlung MS-DOS und AT". Gruppe Datenverarbeitung am MPI für Strömungsforschung Göttingen, Max-Planck-Institut.
- "Tandy 200 Multiplan Manual".
- [[Microsoft C]] [[Microsoft P-Code. Pcode]] Specifications, page 13. (NB. [[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 {{mono. PACK and {{mono. UNPACK instructions converted between the two.)
- (1978). "Microsoft COBOL-80".
- "QWK Mail Packet File Layout".
- (1998-11-17). "CSI Millennium (CSIM) format with CSI Y2K extensions". Commodity Systems, Inc..
- (2016-05-04). "Converting Microsoft Binary Format to IEEE format Using VB 6".
- JerMyster. (2003-07-02). "Help !Anybody know how to convert old M/S MBF value from Qbasic to VB6". Tek-Tips.
- GL88. "Reading Binary Format (QBasic) with C#". Social.msdn.microsoft.com.
- (2013-09-30). "Rmetrics - Reading MetaStock data format in R". R.789695.n4.nabble.com.
- "Google Groups".
- (2018-11-03). "Understanding single precision MBF". boyet.com.
- (2016). "Intel and Floating-Point - Updating One of the Industry's Most Successful Standards - The Technology Vision for the Floating-Point Standard". [[Intel]].
- "VAX Floating Point Numbers".
- "VAX11 780".
- (1998-02-20). "An Interview with the Old Man of Floating-Point". cs.berkeley.edu.
- "IEEE 754: An Interview with William Kahan".
- (1970). "Design of a Computer: The Control Data 6600". [[Scott, Foresman and Company]].
- "Why do we need a floating-point arithmetic standard?".
- "How Java's Floating-Point Hurts Everyone Everywhere".
- (2013-12-21). "Numerical Analysis and Parallel Processing: Lectures given at The Lancaster …". Springer.
- "Names for Standardized Floating-Point Formats".
This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.
Ask Mako anything about Microsoft Binary Format — get instant answers, deeper analysis, and related topics.
Research with MakoFree with your Surf account
Create a free account to save articles, ask Mako questions, and organize your research.
Sign up freeThis content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.
Report