Storing decimal numbers?
Mike15
Posts: 109
Is it possable to store decimal numbers to the internal eeprom? I want to store the thrust cuve of a motor. I know the basic structure of the code needed but not quite sure how to store a decimal number.
Any suggestions would be great
Any suggestions would be great
Comments
As for storing, my idea was to make the number backwards. So if the number is 53.01, store the 53 normally as 00110101 binary, but the .01 is stored as 10 decimal, 00001010 binary. This way, you know how many preceeding zeroes there should be; else, if you stored it normally as 1, you'd never know if there should be twelve 0s or none, it'd always be 00000001.
That make any sense?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
;Long live the SX18AC/DP!
Of course, I'm sure I'm overcomplicating this, you could probably write the whole code without using an binary. I believe either the Stamp or the compiler can figure·it out if you use decimal.·The real trick is getting the program to reverse the decimal value for you, unless your data never changes and you can put it in yourself. And do make sure it keeps track of the byte arrangement, so you pull the right data.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
;Long live the SX18AC/DP!
At least in the case of the thrust curve, multiply all of your right column numbers by 100 and use a WORD sized variable, multiply those in the left-hand column by 10 and I suspect your problems will go away! Just remember to do the appropriate decimal re-locating when displaying them. The Stamp only does interger artithmatic, and only stores interger numbers, but by ranging your values, you can take decimal fractions into consideration rather easily.
If floating point is actually necesssary for some application, there are floating point co-processors available. Just ask about them.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
And if I wanted to make things a little easier when I store both curves I could just multiply all colums by 100. Then when the data is downloade to Excel all I need to do is dvide by 100.
0.018 10.953···· I just tried this and it dose not fit the 16 bit limit. any
0.042 39.215···· suggestions?
0.083 66.888
0.14 72.075
0.223 74.958
0.25 76.694
0.282 80.156
0.315 79.577
0.336 79.577
0.354 81.64
0.365 77.841
0.374 80.724
0.389 76.694
0.455 76.116
0.523 74.39
0.639 70.928
0.722 67.467
0.82 64.005
0.897 58.817
0.992 51.894
1.084 43.824
1.197 34.017
1.268 28.251
1.283 29.987
1.295 27.104
1.328 23.642
1.366 16.719
1.399 9.803
1.435 4.612
1.51 0
Post Edited (Mike15) : 6/25/2006 9:53:17 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chicks dig nerds... but not until after the prom.