Problem with decx method from Simple Numbers
Don M
Posts: 1,653
I am trying to display on PST a series of numbers in decimal form. I wanted each number to only be 2 digits (00 - 99). So I tried using the decx method and I only get the 16 bits (2 blocks of 8) at the beginning of the line and the rest is blank where I would expect it to be 00 00 00 .... 10 10 10 10 or what ever values are containd in s. The TubeFull data prints but the TubeStatus is blank.
Here's the decx method contained in term object:
And here's my code for printing:
Prior to using the decx method I was just using term.dec(s) and it would print out fine.
Help!
Thanks.
Don
Here's the decx method contained in term object:
PUB decx(value, digits) | div ' Added Sept. 6, 2012 '' Returns pointer to zero-padded, signed-decimal string '' -- if value is negative, field width is digits+1 clrstr(@nstr, MAX_LEN) digits := 1 #> digits <# 10 if (value < 0) ' negative value? -value ' yes, make positive nstr[idx++] := "-" ' and print sign indicator div := 1_000_000_000 ' initialize divisor if digits < 10 ' less than 10 digits? repeat (10 - digits) ' yes, adjust divisor div /= 10 value //= (div * 10) ' truncate unused digits repeat digits nstr[idx++] := (value / div + "0") ' convert digit to ASCII value //= div ' update value div /= 10 ' update divisor return @nstr
And here's my code for printing:
pub Tube_Inventory | s, pos TubeFull := 0 ' Clear tube full flags repeat pos from 0 to 15 ' Cycle through all 16 coin tube values if TubeStatus[pos] => $32 ' Check to see which coin tubes are full TubeFull |= 1 << pos ' Set tube full flag for tubes reporting as full repeat pos from 1 to 0 ' Display TubeFull and TubeStatus s := TubeFull.byte[pos] term.bin(s, 8) term.tx(32) repeat pos from 15 to 0 s := TubeStatus[pos] term.decx(s, 2) ' Show decimal value of tube inventory term.tx(32) term.tx(13)
Prior to using the decx method I was just using term.dec(s) and it would print out fine.
Help!
Thanks.
Don
Comments
And here's a screen shot using term.decx(s, 2) method:
decx doesn't print anything: it just creates a string. You have to send its result to the str method to get any output.
-Phil
Thanks again.