Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can VFP read DOUBLEs?

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
Is there a way to read binary file formats in VFP? For instance, I have a file that contains 8-Byte DOUBLEs. I need to read these in and store the numbers they represent in a table. For instance:
[tt]
82 03 5A BA 82 E6 57 C0 = -95.6017
9C F8 6A 47 71 B4 47 40 = 47.4097
[/tt]
Is there any way to do this in Fox?

Ian
 
try FOPEN() and FREAD()... It won't automatically handle type conversions, but it will give you the info as Characters that you can convert and manipulate with ASC(), BITRSHIFT() and BITLSHIFT()
 
Ugh...no, that won't work. I do that already with Integers, but when it comes to Doubles...

The formula for a DOUBLE is:

1 bit: sign (0 is positive, 1 is negative)
11 bits: Exponent (power of 2)
52 bits: Mantissa (fraction expressed as a power of 2 with an implied 1 added)

You multiply the 3 parts together to get the final number.

The part that I just can't figure out is how to calculate that Mantissa. In any case, it's really not worth the effort. I think it would be easier for me to learn how to create a DLL in C++ that will do it for me (C++ can do automatic type conversions).

Assuming no one has any other suggestions, I'll see if I can figure out how to do that instead.

Ian
 
My first answer was just a quickee... I've been looking up just what you've found... the conversion is the pain.

This page (at the bottom) has all the formulas for a Single, which shouldn't be hard to extrapolate to a double:
The one statement on that page I'm still trying to understand is "The exponent field holds the binary representation of 127, and thus the exponent is 0."
 
Ah, I understand that part. While the first bit is the sign of the "whole" number, the exponent can also be positive or negative. So, when the exponent is 0 -> 126 the value is negative (neg + 127), for 127 it's 0, and 128 -> 255 it's positive (minus 127). e.g. -3 exponent is 124, and +3 is 130. Of course those values are again for a Single (w/ 8 bit exponent), they'd need to be a adjusted appropriately for a Double with it's 11 bit exponent!

Rick
 
I actually ended up creating an FLL file in Visual C++ that does the conversion for me. The code is very small and very fast. It receives an 8 byte string, writes it directly to memory, and reads the memory as a DOUBLE value. Then it returns the DOUBLE that it sees in that memory location.

I can post the code if anyone is interested. I would just do it, but the code is at work, and I don't go back in until Monday. LOL

Of course, I could also just post the FLL file.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top