Shop OBEX P1 Docs P2 Docs Learn Events
BS2, Concatenating (not adding) multiple values from GETs into single VAR? — Parallax Forums

BS2, Concatenating (not adding) multiple values from GETs into single VAR?

xanatosxanatos Posts: 1,120
edited 2011-10-26 15:52 in BASIC Stamp
Hi there,

I have several single digit values generated in one slot of my BS2sx programs that are PUT into specific locations.

In another slot I GET those values. They are all single-digit DEC values (0-9).

I need to group them into single variables of three digits each (long story).

Other than GET 1, multiply it by ten, add GET 2, multiply that by 10 and add GET 3 - is there a more eloquent way to concatenate the values? Something equivalent to

someVar = DEC1 (GET 1) & DEC1 (GET 2) & DEC1 (GET 3)

:-)

Thanks,

Dave

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-26 14:16
    There is no elegant way. You have to get the characters one at a time and convert them to binary from ASCII like

    GET 0, X
    Answer = X - "0"
    GET 1, X
    Answer = Answer * 10 + X - "0"

    If the number form allows it, you could do this in a FOR loop
  • xanatosxanatos Posts: 1,120
    edited 2011-10-26 15:52
    Hi Mike, and Thanks... just checking because I always figure there's a better way to do things than what I come up with! :-) Guess it's not always true. Here's what I am using - and it works well:

    TRKMLG = (100 * d6) + (10 * d5) + d4
    TRKMLG2 = (100 * d3) + (10 * d2) + d1

    Then I just use a DEC3 when I send the two variables. Works fine.

    Thanks,

    Dave
Sign In or Register to comment.