Issue when converting Hex to Decimal
Posted: Sun Apr 03, 2022 6:13 pm
I have code that reads portions of binary code from image files. The reading of data is done using the command
To conduct the conversion I have the following function:
This works when the values are small i.e. when the stored pointer points to somewhere near the beginning of the file. Unfortunately when the decimal decode gets large, for example
I wonder if there is a way of stopping livecode from storing the number in scientific notation.
which requires a start position and a length. These two numbers have to be passed as decimal values. This is a problem as the start position and length are stored in hexadecimal which means that the hex values read from the files have to be converted to decimal before the data can be located and read.read from file
To conduct the conversion I have the following function:
Code: Select all
Private function HexToDecimal pBytes,pIsLittleEndian
/* pBytes is a comma seperated list of bytes read from file
*/
## Each loop starts with the units, followed by squared, followed by pwr 4, pwr 6 ...
put the number of items in pBytes into tByteCount
put 0 into tPwr
Switch pIsLittleEndian
Case true
Repeat for each item tByte in pBytes
put tByte into tInt
add tInt*(16^tPwr) to tValue
add 2 to tPwr
end Repeat
break
Case false
Repeat with N = tByteCount down to 1
put (item N of pBytes) into tInt
add tInt*(16^tPwr) to tValue
add 2 to tPwr
end Repeat
break
end Switch
return tValue
end HexToDecimal
livecode pulls a trick and saves the number as0x1332F47 = decimal 20131655
which is not accurate enough.2.01317e+07
I wonder if there is a way of stopping livecode from storing the number in scientific notation.