Binary fields?? 
Author Message
 Binary fields??

I use files created py programs developed in Microsoft
Quick Basic, version 7.0.

I am attempting to move away from all DOS based programming
and into the Windows environment, but I have no control
over the file format that my programs have to read as they
are, and will continue to be, produced by other
program sources in the DOS environment.

I have a problem in that I do not seem to know how to
properly retrieve the information from a random access file
that was originally saved in the Microsoft Binary Format,
specifically, saved using the old MKSMBF$ command.

When I type the variable and retrieve it from the file I
get something like -2.107346E-37 instead of a single
precision number expected!

How can I go about retrieving the correct data from that
field???




Wed, 15 Sep 2004 04:02:07 GMT  
 Binary fields??
I'm going to throw this out there and anyone is welcome to
club me for it...

I think this has to do with  how they are stored in the file
(Qbasic used MBF rather than the IEEE standard...)

Heres a DLL link that will do conversion from and to Msft Binary Format
to 32 bit IEEE standard which VB uses.
    ftp://ftp.softcircuits.com/tools/mbfiee32.zip

I imagine you should read it in from the file using a Get
witha single or double datatype, and then pass that value
to the dll.  It will convert it inplace for you.

Theres a small snip sample in the accompanying text file.

and one from the MVPs...
http://www.microdexterity.com/

HERES SOME STUFF I FOUND ALONG THE WAY...

********************************************************************

Double Precision Reals are treated as Singles.

********************************************************************

MS Binary Format / IEEE conversion

Question

Couple of questions:
1.  Does Delphi store real numbers in "Microsoft Binary Format" or "IEEE"?
2.  How can I call a small segment of assembler code within my Delphi code?
Can I embed assembler routines within Delphi?  Please note my assembler
exposure is very limited, but I have also wondered how I can do this, in
both C and now Delphi.

Answer

A:
"whatever the base-level machine uses" is not so straightforward before
Intel's 80x87 numeric coprocessors came along.  I'm not sure if the 80x86
processors had any native instructions to perform floating point
arithmetic.  This could be why Microsoft created their own proprietary
format for floating point numbers; they had to do all the arithmetic
themselves, using their own runtime library.  Today, the 80x87 makes the
arithmetic automatic, and IEEE is now the standard.

Delphi does store the following floating point types in IEEE format:
  Single      4 bytes
  Double      8 bytes
  Extended   10 bytes

Note that Real (6 bytes) is not on this list.  I may be wrong, but I
believe Real is an intrinsic Pascal type; its existence may predate the
80x87.

[Aside:  Delphi's online help says that, by default (via the $N+ compiler
directive), the compiler will generate code to perform ALL floating point
calculations using 80x87 instructions, including Real types.  So either the
compiler will generate calls to a runtime library to handle Real types, or
else I am completely wrong about the above! :) ]

Anyway, in checking Visual Basic's online help, I see that its data types
also include Single and Double, which are also IEEE, and are identical to
Delphi's Single and Double types.  However, there is no mention of
"Microsoft Binary Format".

I then dropped down to DOS and ran QBasic, which is Microsoft's old
QuickBasic interpreter that is now included in DOS.  If you check its
online help, you will see the following:

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
MKSMBF$ and MKDMBF$ convert IEEE-format numbers to Microsoft-Binary-format
numeric strings that can be stored in FIELD statement string variables.
CVSMBF and CVDMBF convert those strings back to IEEE-format numbers.

MKSMBF$(single-precision-expression!)
MKDMBF$(double-precision-expression#)
CVSMBF (4-byte-numeric-string)
CVDMBF (8-byte-numeric-string)

   Function    Returns
   ========    ============================================================
   MKSMBF$     A 4-byte string containing a Microsoft-Binary-format number
   MKDMBF$     An 8-byte string containing a Microsoft-Binary-format number
   CVSMBF      A single-precision number in IEEE format
   CVDMBF      A double-precision number in IEEE format

   These functions are useful for maintaining data files created with
   older versions of Basic.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

So, to sum up, if you want to access your "MetaStock" files, I think you
have 3 choices.

1.  Write your program in QBasic/DOS

2.  Find substitutes (hopefully compatible with Delphi) for the conversion
    functions mentioned above.

3.  Write these functions yourself.  You will have to find documentation
    for the bitwise layout of the old "Microsoft Binary Format" Single and
    Double types, perhaps in MS's old Basic manuals.

**************************************************************************

9. any tips on mixed language programming?

ANSWER
~~~~~~

This is a real common subject. the solutions is not quite
that simple however. The solution depends entirely on the specific
implementations of the languages you are using, but here are some
general guidelines.

1. Try to match up system specific options such as memory models,
   floating point formats, etc..
2. Try to account for the language specific features such as
   BASIC's pass by reference parameters versus C's pass by value.
   As well as C's underscore prefixing of public labels and C++'s
   name mangling.
3. Remember to 'Declare' the external procedures as required.
4. For powerbasic, a sheet with the required settings for Borland C
   can be obtained from their ftp server: ftp.powerbasic.com

**************************************************************************

16. Why does .321 come out as .3219994?

ANSWER
~~~~~~

The IEEE floating point format is flawed in that it can not
represent all fractional values perfectly, thus sometimes it
must represent a number close to the value. Sometimes this shows
up in your program, often more than not, the implementation performs
special rounding with floating point numbers so you never see it.
For display purposes using a formatted print and limiting it to
7 decimal places for SINGLE or 15 for DOUBLE will usually handle
this for you. For a better understanding, the fractional part is
calculated using 2 raised to a negative exponent [2 ^ -1 = .5],
so try it yourself with a few numbers and see what you come up with.

**************************************************************************

17. What is MBF?

ANSWER
~~~~~~

Microsoft Binary Format is an alternate Floating Point Format
to the IEEE 747 standard formats. It was commonly used in the
70's and may be run across in old software/data files. More
information on the format can be retrieves from www.borland.com
or ftp.borland.com along with C source code to convert between the
two. Perhaps Peter will translate in the Code FAQ for uses of
other Basics. The Microsoft Binary Format was given up for the IEEE
formats because its accuracy was not as good and to comply with
the Intel 80x87 FPU for faster calculations using the FPU.

**************************************************************************

D.

| I use files created py programs developed in Microsoft
| Quick Basic, version 7.0.
|
| I am attempting to move away from all DOS based programming
| and into the Windows environment, but I have no control
| over the file format that my programs have to read as they
| are, and will continue to be, produced by other
| program sources in the DOS environment.
|
| I have a problem in that I do not seem to know how to
| properly retrieve the information from a random access file
| that was originally saved in the Microsoft Binary Format,
| specifically, saved using the old MKSMBF$ command.
|
| When I type the variable and retrieve it from the file I
| get something like -2.107346E-37 instead of a single
| precision number expected!
|
| How can I go about retrieving the correct data from that
| field???
|

|



Wed, 15 Sep 2004 05:08:02 GMT  
 Binary fields??
Very much appreciated!  Sure makes things much simpler!


Quote:
>I'm going to throw this out there and anyone is welcome to
>club me for it...

>I think this has to do with  how they are stored in the file
>(Qbasic used MBF rather than the IEEE standard...)

>Heres a DLL link that will do conversion from and to Msft Binary Format
>to 32 bit IEEE standard which VB uses.
>    ftp://ftp.softcircuits.com/tools/mbfiee32.zip

>I imagine you should read it in from the file using a Get
>witha single or double datatype, and then pass that value
>to the dll.  It will convert it inplace for you.

>Theres a small snip sample in the accompanying text file.

>and one from the MVPs...
>http://www.microdexterity.com/

>HERES SOME STUFF I FOUND ALONG THE WAY...

>********************************************************************

>Double Precision Reals are treated as Singles.

>********************************************************************

>MS Binary Format / IEEE conversion

>Question

>Couple of questions:
>1.  Does Delphi store real numbers in "Microsoft Binary Format" or "IEEE"?
>2.  How can I call a small segment of assembler code within my Delphi code?
>Can I embed assembler routines within Delphi?  Please note my assembler
>exposure is very limited, but I have also wondered how I can do this, in
>both C and now Delphi.

>Answer

>A:
>"whatever the base-level machine uses" is not so straightforward before
>Intel's 80x87 numeric coprocessors came along.  I'm not sure if the 80x86
>processors had any native instructions to perform floating point
>arithmetic.  This could be why Microsoft created their own proprietary
>format for floating point numbers; they had to do all the arithmetic
>themselves, using their own runtime library.  Today, the 80x87 makes the
>arithmetic automatic, and IEEE is now the standard.

>Delphi does store the following floating point types in IEEE format:
>  Single      4 bytes
>  Double      8 bytes
>  Extended   10 bytes

>Note that Real (6 bytes) is not on this list.  I may be wrong, but I
>believe Real is an intrinsic Pascal type; its existence may predate the
>80x87.

>[Aside:  Delphi's online help says that, by default (via the $N+ compiler
>directive), the compiler will generate code to perform ALL floating point
>calculations using 80x87 instructions, including Real types.  So either the
>compiler will generate calls to a runtime library to handle Real types, or
>else I am completely wrong about the above! :) ]

>Anyway, in checking Visual Basic's online help, I see that its data types
>also include Single and Double, which are also IEEE, and are identical to
>Delphi's Single and Double types.  However, there is no mention of
>"Microsoft Binary Format".

>I then dropped down to DOS and ran QBasic, which is Microsoft's old
>QuickBasic interpreter that is now included in DOS.  If you check its
>online help, you will see the following:

>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>MKSMBF$ and MKDMBF$ convert IEEE-format numbers to Microsoft-Binary-format
>numeric strings that can be stored in FIELD statement string variables.
>CVSMBF and CVDMBF convert those strings back to IEEE-format numbers.

>MKSMBF$(single-precision-expression!)
>MKDMBF$(double-precision-expression#)
>CVSMBF (4-byte-numeric-string)
>CVDMBF (8-byte-numeric-string)

>   Function    Returns
>   ========    ============================================================
>   MKSMBF$     A 4-byte string containing a Microsoft-Binary-format number
>   MKDMBF$     An 8-byte string containing a Microsoft-Binary-format number
>   CVSMBF      A single-precision number in IEEE format
>   CVDMBF      A double-precision number in IEEE format

>   These functions are useful for maintaining data files created with
>   older versions of Basic.
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

>So, to sum up, if you want to access your "MetaStock" files, I think you
>have 3 choices.

>1.  Write your program in QBasic/DOS

>2.  Find substitutes (hopefully compatible with Delphi) for the conversion
>    functions mentioned above.

>3.  Write these functions yourself.  You will have to find documentation
>    for the bitwise layout of the old "Microsoft Binary Format" Single and
>    Double types, perhaps in MS's old Basic manuals.

>**************************************************************************

>9. any tips on mixed language programming?

>ANSWER
>~~~~~~

>This is a real common subject. the solutions is not quite
>that simple however. The solution depends entirely on the specific
>implementations of the languages you are using, but here are some
>general guidelines.

>1. Try to match up system specific options such as memory models,
>   floating point formats, etc..
>2. Try to account for the language specific features such as
>   BASIC's pass by reference parameters versus C's pass by value.
>   As well as C's underscore prefixing of public labels and C++'s
>   name mangling.
>3. Remember to 'Declare' the external procedures as required.
>4. For PowerBasic, a sheet with the required settings for Borland C
>   can be obtained from their ftp server: ftp.powerbasic.com

>**************************************************************************

>16. Why does .321 come out as .3219994?

>ANSWER
>~~~~~~

>The IEEE floating point format is flawed in that it can not
>represent all fractional values perfectly, thus sometimes it
>must represent a number close to the value. Sometimes this shows
>up in your program, often more than not, the implementation performs
>special rounding with floating point numbers so you never see it.
>For display purposes using a formatted print and limiting it to
>7 decimal places for SINGLE or 15 for DOUBLE will usually handle
>this for you. For a better understanding, the fractional part is
>calculated using 2 raised to a negative exponent [2 ^ -1 = .5],
>so try it yourself with a few numbers and see what you come up with.

>**************************************************************************

>17. What is MBF?

>ANSWER
>~~~~~~

>Microsoft Binary Format is an alternate Floating Point Format
>to the IEEE 747 standard formats. It was commonly used in the
>70's and may be run across in old software/data files. More
>information on the format can be retrieves from www.borland.com
>or ftp.borland.com along with C source code to convert between the
>two. Perhaps Peter will translate in the Code FAQ for uses of
>other Basics. The Microsoft Binary Format was given up for the IEEE
>formats because its accuracy was not as good and to comply with
>the Intel 80x87 FPU for faster calculations using the FPU.

>**************************************************************************

>D.


>| I use files created py programs developed in Microsoft
>| Quick Basic, version 7.0.
>|
>| I am attempting to move away from all DOS based programming
>| and into the Windows environment, but I have no control
>| over the file format that my programs have to read as they
>| are, and will continue to be, produced by other
>| program sources in the DOS environment.
>|
>| I have a problem in that I do not seem to know how to
>| properly retrieve the information from a random access file
>| that was originally saved in the Microsoft Binary Format,
>| specifically, saved using the old MKSMBF$ command.
>|
>| When I type the variable and retrieve it from the file I
>| get something like -2.107346E-37 instead of a single
>| precision number expected!
>|
>| How can I go about retrieving the correct data from that
>| field???
>|

>|



Sat, 18 Sep 2004 11:09:47 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ole field (long binary fields)

2. Convert String-buffer-written binary field to Byte-array-written binary field?

3. Convert String-buffer-written binary field to Byte-array-written binary field?

4. Problem with long binary fields

5. Long Binary Fields

6. Just curious: Binary field type

7. CDO Problem with binary field

8. VBScript & SQLServer 6.5 Binary fields

9. Saving OLE object from VB to Access Database binary field

10. Accessing SQL Binary Fields thru VB

11. Accessing binary fields from DB2 via ODBC

12. Binary Fields with ODBCdirect ?

 

 
Powered by phpBB® Forum Software