Which string Object?
bambino
Posts: 789
I have a buffer(2600 words Long) that contains a log from a A2D converter.
I have written a routine that converts the numbers to a decimal output, but it is unpredictable. Anyway I was wondering, since I have not really worked with any of the float objects yet, which one would be best to use. I will probably be able to use spin(Speed not necessary). The numbers·range from 0 to 500 With two decimal places. ie: I need to convert 49999 to 499.99.
I just need to convert the pseudo number to two decimal places and record it to an sd card.
The routine I have wrote to convert the number to ascii for storage on the card works fine and the math used to convert the 16 bit converter numbers to between 0 and 500 work fine, but I have hurt my head tring to get around this decimal thing.
My code simply takes the pseudo number, saves it to varX and varY, multiplies·varX by 100 and devides by 100 to get the integer. then I subtract varX from varY to get the decimals. It sounds fine in theory but what I get on my curve output from the buffer has periodic spikes in the decimal values.
Anyway, getting to the point, what object do I need to look into using? Numbers, FloatString, or maybe Float32?
Thanks for any input you may have!
I have written a routine that converts the numbers to a decimal output, but it is unpredictable. Anyway I was wondering, since I have not really worked with any of the float objects yet, which one would be best to use. I will probably be able to use spin(Speed not necessary). The numbers·range from 0 to 500 With two decimal places. ie: I need to convert 49999 to 499.99.
I just need to convert the pseudo number to two decimal places and record it to an sd card.
The routine I have wrote to convert the number to ascii for storage on the card works fine and the math used to convert the 16 bit converter numbers to between 0 and 500 work fine, but I have hurt my head tring to get around this decimal thing.
My code simply takes the pseudo number, saves it to varX and varY, multiplies·varX by 100 and devides by 100 to get the integer. then I subtract varX from varY to get the decimals. It sounds fine in theory but what I get on my curve output from the buffer has periodic spikes in the decimal values.
Anyway, getting to the point, what object do I need to look into using? Numbers, FloatString, or maybe Float32?
Thanks for any input you may have!
Comments
I don't have much dev time this weekend, and I didn't want to spend the whole time reading the wrong thing!
Have a good weekend!
I think you made a typo in you note. (Or I didn't understand your number conversion)
i:=VarX/100 gives you the integer portion
j:+Varx//100 gives you your remainder...
So... (in psuedo-code) you would just concantonate str(i) + string(".") + string(j). Which string object to use?... I have no clue[noparse]:)[/noparse]
Eventually, I'll have the same problem. So, when you do get it working, please post some snippets.
Thanks
Rich
I used the floatstring.object over the weekend with the floatmath.
The routine I wrote was taking around 20 seconds to convert the whole buffer.
I switched from floatmath to float32 and was blown away. Less than 3 seconds.
Plus, the way the numbers are formatted useing the float to string function, my routine for storeing the numbers to the sd card is obsolete. I just read the string into an array and send it own. Its great!
As for the psuedo code I can only say it was working before I switched anolog convertors. The first was a 12 bit and the operation worked. The second is a 16 bit and the decimal values kept spiking no matter how I filtered it.
I was doing it that way because I thought I could, and because I did not want the extra code of the float objects taking up room. However, after I joined floatstring and float32 into one object and commented out the unused code, it takes up very little room.
If you do decide to go with pseudo code:
var
long rawdata
long int
long deci
pub printFloat
int :=((rawdata/100)*100)
deci := (rawdata-int)
com.dec(int)
com.str(String("."))
com.dec(deci)
com.crlf
As I said though this produces unexpected results when viewed through some 2600 data sets(then again it may be something else in my code that was causeing the problems)
Anyway thanks again to Mike for helping me to focus my efforts.
Sorry about the formatting this computer want give me a code window to type in!
Post Edited (bambino) : 6/4/2007 6:45:47 PM GMT