Shop OBEX P1 Docs P2 Docs Learn Events
A buffer string / number question — Parallax Forums

A buffer string / number question

Don MDon M Posts: 1,652
edited 2014-04-23 19:51 in Propeller 1
In a buffer that consists of 80 characters I have 9 of those characters that represent a number. In this case it is a 9 digit number- 000000001.

How do I convert these 9 characters into an actual number that I can use to do math or comparisons with?

I copy the 9 characters from the large buffer to the smaller buffer with this:
  bytemove(@Buffer2, @Work_Buffer[64], 9)


I tried this to display the number- debug.dec(@buffer2) and debug.dec(buffer2) and neither produced the result of 000000001 or 1.

If I do an index repeat from 0 to 8 with debug.dec(@buffer2) I get 484848484848484849 which is the decimal representation of each ASCII character.

I just want to display either 000000001 (with a fixed number of digits method) or just 1 as a number and not an ASCII equivalent.

Thanks.

Comments

  • Don MDon M Posts: 1,652
    edited 2014-04-23 19:27
    Come to think of it I probably need to make buffer2 into just a single long and then multiply and shift each byte to make up the whole number into the long. Is that correct?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-04-23 19:51
    There are methods in the "Numbers" object in the Propeller Tool Library to convert numbers to and from ASCII characters.
  • Don MDon M Posts: 1,652
    edited 2014-04-23 19:51
    I found the StrToDec method. That will work for me I think.
Sign In or Register to comment.