Shop OBEX P1 Docs P2 Docs Learn Events
Int and Hex toString — Parallax Forums

Int and Hex toString

mcstarmcstar Posts: 144
edited 2008-12-19 21:02 in Propeller 1
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...

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

  • StefanL38StefanL38 Posts: 2,292
    edited 2008-12-19 21:02
    Hello mcstar,

    in the FullDuplexSerial-object you will find methods
    dec, hex, bin that will do that

    best regards

    Stefan
Sign In or Register to comment.