Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to read a 32bit float from disk
Message
 
À
17/10/2001 11:52:02
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00569467
Message ID:
00921113
Vues:
19
Dragan,
Sergey passed this on to me. I need to do 4 byte floating point. You mention below that it can be done with some "tweaking". Well, what do I tweak?
TIA


>
>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
Beer is proof that God loves man, and wants him to be happy. - Benjamin Franklin
John J. Henn
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform