Int and Hex toString
mcstar
Posts: 144
For floats there is a convenient method called FloatToString that returns a pointer to a text version of the float you give it.... so
for instance 1.0 is converted to $31 $2E $30 $00. What's great about this, is that the pointer it returns can be directly used to create csv files using the fsrw driver like this...
Now that I've shared my tidbit for the day, my question, has anyone created similar methods for Ints and Hex values? If so, please share. To be explicit I'm looking for two methods, one that takes a long and returns a pointer to an integer formatted string and the other that formats it has a hex string.
So, for 1 the DecToString should return $31 $00
and for HexToString it should allow you to specify the number of digits to pad with 0's so it would return a pointer to $30 $31 $00 if you specified 2 digits
Thanks
for instance 1.0 is converted to $31 $2E $30 $00. What's great about this, is that the pointer it returns can be directly used to create csv files using the fsrw driver like this...
pstr := fs.FloatToString(x) sd.pwrite(pstr,strsize(pstr))
Now that I've shared my tidbit for the day, my question, has anyone created similar methods for Ints and Hex values? If so, please share. To be explicit I'm looking for two methods, one that takes a long and returns a pointer to an integer formatted string and the other that formats it has a hex string.
So, for 1 the DecToString should return $31 $00
and for HexToString it should allow you to specify the number of digits to pad with 0's so it would return a pointer to $30 $31 $00 if you specified 2 digits
Thanks
Comments
in the FullDuplexSerial-object you will find methods
dec, hex, bin that will do that
best regards
Stefan