|
Post by rabaggett on Jan 8, 2019 10:44:17 GMT -5
Hello,
I have a binary file in which numbers are represented as 32 bit floats. I hope to bring these into my program for manipulation, and then save them back to the file, again as 32 bit floats.
I understand how to get the bytes comprising the floats from the files, and how to reassemble these bytes into the file, the problem is converting them to LibertyBasic numbers, and back. Is there a call or algorithm that already exists to do this?
Thanks!
|
|
|
Post by tsh73 on Jan 8, 2019 15:17:16 GMT -5
Found on Bay6 forum via InternetWayback Machine Function CVS( SBits$ ) '-- Equivalent to QB's CVS function. '-- Provided freely by Brent D. Thorn. '-- http://www.b6sw.com If Len(SBits$) >= 4 Then CVS = Asc(SBits$) _ + 256 * Asc(Mid$(SBits$, 2, 1)) _ + 65536 * Asc(Mid$(SBits$, 3, 1)) _ + 16777216 * Asc(Mid$(SBits$, 4, 1)) Struct local1, D As Double Open "oleaut32" For DLL As #oleaut32 CallDLL #oleaut32, "VarR8FromR4", _ CVS As ULong, local1 As Struct, _ ret As Long Close #oleaut32 CVS = local1.D.struct End If End Function Function MKS$( SNum ) '-- Equivalent to QB's MKS$ function. '-- Provided freely by Brent D. Thorn. '-- http://www.b6sw.com MKS$ = Space$(4) Open "oleaut32" For DLL As #oleaut32 CallDLL #oleaut32, "VarR4FromR8", _ SNum As Double, MKS$ As Ptr, _ ret As Long Close #oleaut32 If ret <> 0 Then MKS$ = "" End Function
(whole page web.archive.org/web/20071006003759/https://www.b6sw.com/forum/content.php?mode=snips&t=206)
|
|
|
Post by rabaggett on Jan 27, 2019 11:38:05 GMT -5
Thanks! can't wait to try it!
|
|