[futurebasic] Re: [FB] File Issues with Reading Single Var Arrays

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2014 : Group Archive : Group : All Groups

From: David Herron <caverdave@...>
Date: Sat, 18 Oct 2014 12:00:01 -0600
Oops.  Actually, the first line of the function needs to be:

local fn MyConvertBCDtoSingle!(OldVal!)

The function name needs to have an apostrophe in it, to signify that it returns a SINGLE.
Otherwise, it always returns Integer results.


David Herron
CaverDave@...


On Oct 17, 2014, at 9:31 PM, David Herron <CaverDave@...> wrote:

> Well, I have finally solved the mystery of my old file data.  As expected, it was floating point values, saved in Binary-Coded-Decimal format.
> After examining the file data at length, in hexadecimal. and comparing to known data, I have finally figured out the format.
> Then, after some adventures, I wrote a function to convert that data to FB5 Single format.
> 
> My updated program still reads the file data directly into a var array, but now I can convert the individual values to their proper format.
> The function code is pretty crude, and round-about, but appears to do the job.
> 
> Pretend each variable is actually a 4-byte long, convert to 8-digit Hexadecimal string, then parse out and rearrange the data.
> Then deal with the sign, decimal point, and exponent value and sign.  I’m sure it could be done faster, but to works fine for me.
> 
> Here is the crude function in question
> 
> 
> local fn MyConvertBCDtoSingle(OldVal!)
> dim as byte ExpVal
> dim as byte ExpSign
> DIM as str255 HSTR$
> dim as str255 MyNewStr$
> dim  MyTemp&
> dim  MyNewVal!
> MyTemp& = Peek Long (varptr(OldVal!)
> HSTR$ = HEX$( MyTemp& )
> ExpVal = val("&H"+Mid$(HSTR$,7,2))
> ValSign = ExpVal and &H80
> ExpSign = ExpVal and &H40
> ExpVal = ExpVal and &H3F
> MyNewStr$ = Mid$(HSTR$,5,1) + "." + Mid$(HSTR$,6,1) + Mid$(HSTR$,3,1) 
> MyNewStr$ = MyNewStr$ + Mid$(HSTR$,4,1) + Mid$(HSTR$,1,1) + Mid$(HSTR$,2,1)
> MyNewVal! = val(MyNewStr$)
> if ValSign then MyNewVal! = - MyNewVal!
> long if ExpSign
> ExpVal = 64-ExpVal
> MyNewVal! = MyNewVal! / (10^ExpVal)
> xelse
> MyNewVal! = MyNewVal! * (10^ExpVal)
> end if
> end fn = MyNewVal!
> 
> 
> David Herron
> CaverDave@...