Shop OBEX P1 Docs P2 Docs Learn Events
Character — Parallax Forums

Character

GreyBox TimGreyBox Tim Posts: 60
edited 2005-11-16 04:05 in General Discussion
I'm interested to see if anyone already has the code for grabbing a character from a variable·like the "DIG" function in Pbasic.

i.e.: if I want to grab character "0" of 255 I would put it "var DIG 0" and be replied with the character "5"

Thoughts?

-Tim

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-16 03:49
    I wrote this SX/B·subroutine and it seems to work fine for bytes:

    ' Use: theDigit = DIG value, whichPos

    DIG:
    · temp1 = __PARAM1·········· ··' save value
    · temp2 = __PARAM2·········· ··' position
    · temp3 = 0
    · IF temp2 < 3 THEN
    ··· DO WHILE temp2 > 0
    ····· temp1 = temp1 / 10
    ····· DEC temp2·
    ··· LOOP
    ··· temp3 = temp1 // 10···
    · ENDIF
    · RETURN temp3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • GreyBox TimGreyBox Tim Posts: 60
    edited 2005-11-16 03:54
    Simple - yet sexy!

    I'll give it a whirl tonigt when I get home - speaking of which, what are you still doing working ths late? I thought I was the only guy staying till 9PM these days...

    Cheers!

    -Tim
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-16 03:55
    When one works from home "office hours" are defined as those when one is not sleeping....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • GreyBox TimGreyBox Tim Posts: 60
    edited 2005-11-16 03:56
    In fact, the more I look at that code, I can see that's probably very close (if not spot-on) to how you guys did that in Pbasic...

    Again Thanks!

    -Tim
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-16 03:57
    I don't have access to the BASIC Stamp source code so I don't know -- but there is a certain logic that most programmers would agree upon.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • GreyBox TimGreyBox Tim Posts: 60
    edited 2005-11-16 04:05
    I define "off hours" as those minutes when I'm not commuting between home and the office (and back) - and when I'm so tired that the keybaord becomes my 'sleeping mask". Ahh the joys of supporting the tech industry...

    -Tim
Sign In or Register to comment.