Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to read a 32bit float from disk
Message
From
17/10/2001 11:52:02
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
17/10/2001 08:19:12
Liam O'Hagan
O'Hagan Programming Ltd
Ireland
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00569467
Message ID:
00569663
Views:
20
>Hi All,
>
>Has anyone previously read 32 bit floats from disk? I'm importing information from a disk file that contains Character and numeric information. The character info is no problem and I can convert 16 bit Ints easily. However, floats are stored in a totally different format. Has anyone cracked this before?

This converts VFP's B format, which is 64-bit float. Tweaking it you can get the 32 bit version:
Function bton
*+ douBle string --> numeric
* takes a 8 byte string with IEEE representation of a long real
* structure:
* 7. byte:  7 bit sign
*	6-0 bit exponent upper
* 6. byte, bits 7-4 exponent lower. Exponent has 0x400 added
*    bits 3-0 mantissa. Mantissa is normalised, ie. assume 1 for first bit
* bytes 5-0 rest of mantissa
* returns a number.
*-
Lpara _s
Dime bajt(8)
For j=1 to 8
	bajt[j]=asc(subs(_s,j))
Endf
znak=iif(bittest(bajt[8], 7), -1, 1)
eksp=bitand(bajt[8],127)*16+bitrshift(bajt[7], 4)
*eksp=bitand(eksp+1025, 1023)
eksp=eksp-1023
mant=1+bitand(bajt[7], 15)/16
dv=4096
For j=6 to 1 step -1
	mant=mant +bajt(j)/dv
	dv=dv*256
Endf
rez=mant*2**eksp*znak
Retu rez

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform