Extended 80-bit hex floating point (IEEE?) conversion
Jim Ault
jimaultwins at yahoo.com
Fri Feb 4 22:44:32 EST 2011
On Feb 4, 2011, at 7:01 PM, stephen barncard wrote:
> I could use some help here.. I want to detect other sample rates.
> The ones
> above were determined by examining them in sound files with known
> rates.
>
> How would I convert these 80 bit hex floating point numbers to the
> values
> shown and back again?. Baseconvert doesn't work with this many hex
> characters. (linked is some C source...)
> surely this can be done in Livecode...
I think that
binaryDecode
would help you here.
I have used it in the past to handle mixed text ascii and bit-encoded
data conversions
--- example from 5 years ago
parsing a 32 bit string, then
resolving the stored value for a stock trading program
The reason for the compressions of the data is that the data feed
protocol was designed in the days of dial up-acoustic couplers and
bytes really mattered.
(This was just after the days of using acoustic couplers to send morse
code between computers at Western Union :-)
----single range to a single variable
function showInt32 binStr
--put "011111000110000000" into binStr
put "B32" into cc
get binaryDecode(tolower(cc),binStr,theHex)
--if "0" is not in theHex then breakpoint
put 0 into summ
put the length of theHex into maxx
repeat with x = 0 to maxx
put 2^(maxx-x-1) into mult
put 2^(x) into mult
--add char (x+1) of binStr * mult to summ
get char x+1 of theHex
get it * mult
add it to summ
end repeat
--put summ & " < " & theHex
return summ
end showInt32
--------------------------
Here is a way of parsing a long ascii string of values into their
variable names you define
This converts UDP packets from an industry data source fed real time.
Note that numHses will vary with each packet, so the repeat loop
handles this changing length format
I am using trick to parsing to a 'remainder' variable by
'sum(firstInt, secondInt, thirdInt)
thus 'a49a1a2a(INT)' is the correct string to pass to the fuction as
'str'
on convertRU tempp --long ascii string
put "a49a1a2a"&length(tempp)-sum(49,1,2) into str
put binarydecode(str,tempp,raceData,rcStatus,numHses,remainder)
into success
put remainder into tempp
put numHses*1 into numHses
put "a"&numhses&"a"&length(tempp)-sum(numhses) into str
put binarydecode(str,tempp,statusEnt,remainder) into success
put remainder into tempp
put "a2a"&length(tempp)-sum(2) into str
put binarydecode(str,tempp,numBetTypes,remainder) into success
put remainder into tempp
repeat with x = 0 to (numBetTypes-1)
put char (x*3+1) to (x*3+3) of remainder &tab after poolList
end repeat
put char ((x+1)*3+1) to -1 of remainder into remainder
delete last char of poolList
put "raceData,rcStatus,numHses, statusEnt, numBetTypes, poolList"
into doVars
repeat for each item ITM in doVars
put value(ITM) & tab after output
end repeat
put space before char 3 of output
put output & cr before fld trappedMsgsUserView
end convertRU
Hope this helps
Jim Ault
Las Vegas
More information about the use-livecode
mailing list