Shop OBEX P1 Docs P2 Docs Learn Events
Spin equivalent of PBASIC's DIG operator — Parallax Forums

Spin equivalent of PBASIC's DIG operator

SSteveSSteve Posts: 808
edited 2006-05-14 14:40 in Propeller 1
Looking through the Spin documentation, I don't see an equivalent for the PBASIC "DIG" operator. Is this the closest thing for "theDigit = value DIG 1"?
theDigit := (value / 10) // 10

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

Post Edited (SSteve) : 5/14/2006 2:14:07 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-05-14 02:34
    You've got it! I'm sure that the DIG operator was included in PBASIC because of speed constraints with multiplication and division. For the Propellor, it's not really a problem.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-14 02:52
    The cool thing about Spin is that you can extend it through custom methods -- this should work:

    PUB dig(value, position) : digit

    · if postion > 0
    ··· repeat position
    ····· value /= 10

    · digit := value // 10
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • cgraceycgracey Posts: 14,206
    edited 2006-05-14 06:01
    John, it's even better than that!

    'REPEAT <count>' where count==0 won't repeat anything. So, you don't need that test for >0. I'll get rid of that line:
    Jon Williams (Parallax) said...



    PUB dig(value, position) : digit

    · repeat position
    ··· value /= 10

    · digit := value // 10
    ·
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-14 14:40
    That was my original inclination but I didn't have my Propeller board hooked-up (was teaching EFX products yesterday) to test. Thanks for the correction, Chihp.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.