Shop OBEX P1 Docs P2 Docs Learn Events
Help getting Decimals into string.SOLVED — Parallax Forums

Help getting Decimals into string.SOLVED

pgbpsupgbpsu Posts: 460
edited 2009-10-30 19:51 in Propeller 1
I'm trying to put some numbers into a string but can't figure out how to do it. I'd like to construct a string that has a filename followed by
some number of spaces followed by the size of the file. Like this:
09103016.04M          509040




To this end, I've established space in HUB memory called temp_buf to hold all these characters.

I can successfully copy the filename into this buffer, and I can move over 10 spaces (as above), but what I can't get to work is using
Num.ToStr to add the filesize to the latter part of the buffer so the complete string would look like the line above.

This thread

http://forums.parallax.com/showthread.php?p=692502


made me think the code below would work. But it doesn't. Output from that code is below.
long temp_buf[noparse][[/noparse]20] 

bytefill(@temp_buf,0,80)    ' zero out temp_buff; now treating it as BYTES rather than LONGS
temp_buf[noparse][[/noparse]0] := ( ( ACQ_STATE | %0000_0000 )<< 24 )| gps.Num_SV << 18 | Num.FromStr(gps.gps_time, NUM#DEC)
temp_buf := cnt '                                                                       
temp_buf :=  1  ' Is this data or not?  0=Date; NOT 0=NOT DATA                          

bytefill(@temp_buf+12," ",28)   ' put 28 spaces into temp_buf which we'll overwrite later  

csum:=strsize(@tbuf)
bytemove(@temp_buf+12,@tbuf,csum)             ' copy filename into temp_buf

SO FAR SO GOOD

csum := strsize(Num.ToStr(sdfat.getfilesize,Num#SDEC11))
ascii:= Num.ToStr(sdfat.getfilesize,Num#SDEC11)         
bytemove(@temp_buf+28,ascii,csum+1)           ' copy ASCII number into buffer well to the left of our filename but still before the end of the buffer.          
    

Here's the resulting buffer (skipping the first 12 bytes which don't contain text, but do seem to work) printed as hex and ASCII 
with offset from beginning of buffer on the bottom 
0  9  1  0  3  0  1  6  .  0  4  M                                             0         
30 39 31 30 33 30 31 36 2E 30 34 4D 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 00 00 00 00 00 00 00 00 00
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47




Shouldn't the the contents beginning as ascii and continuing for csum bytes be copied into temp_buf beginning at offset 28? In this
case that should be 509040 which is the length of the file named 09103016.04M

The only thing I can see that's different between my code and the example I was trying to follow is that they may have declared
their buffer as byte whereas I declared mine as long. But why should that matter if I'm addressing it by it's base and offset? Or am I not actually doing that?

Any suggestions or comments would be greatly appreciated.
Thanks,
Peter

I found my problem and it had nothing to do with the code above.

Post Edited (pgbpsu) : 10/30/2009 8:36:16 PM GMT
Sign In or Register to comment.