Shop OBEX P1 Docs P2 Docs Learn Events
P1 SPIN TO P2 SPIN — Parallax Forums

P1 SPIN TO P2 SPIN

pic18f2550pic18f2550 Posts: 400
edited 2022-01-07 14:31 in PASM2/Spin2 (P2)

Hello,
The P2 cannot translate the P1:

PRI InBaseRange(Char, Base): Value
''Compare Char against valid characters for Base (1..16) (adjusting for lower-case automatically).
''Returns 0 if Char outside valid Base chars or, if valid, returns corresponding Value+1.
Value := ( Value -= (Char - $2F) * (Char => "0" and Char =< "9") + ((Char &= $DF) - $36) * (Char => "A" and Char =< "F") ) * -(Value < ++Base)
                                         ^
                                         |
He always wants to put a bracket here. --+

How would I have to modify this to make it work?
Thanks.

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2022-01-08 01:33

    JonnyMac has a doc which has the operators which require changing. Hope he will chime in.

    IIRC => changes to >= etc

  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-01-11 18:47

    The P2 cannot translate the P1:

    As Ray pointed out, just change => to >=, and =< to <=.

    That said, I think this is a cleaner implementation (P2 version):

    pri in_base_range(char, base) : result
    
    '' Returns 1..16 if char is legal (bin, quart, oct, dec, hex)
    
      if ((char >= "a") && (char <= "z"))                           ' convert alpha to uppercase
        char &= %11011111
    
      result := lookdown(char : "0".."9", "A".."F")                 ' check range bounds
    
      if (result > base)                                            ' 0 if out-of-bounds
        result := 0  
    
  • You have to come up with something like that first. "=> changes to >="
    I didn't get that error, because I assumed that the parser would correct it.
    Again what learned. :)
    Thanks

  • JonnyMacJonnyMac Posts: 9,104
    edited 2022-01-11 18:53

    I made the attached document for myself (it's based on another document Chip has posted) when I started porting my P1 code to the P2. Maybe it will help you. If you find any errors, please let me know.

  • Duane DegnDuane Degn Posts: 10,588
    edited 2022-01-12 02:45

    @Cluso99 said:
    JonnyMac has a doc which has the operators which require changing.

    Here's a link to the list Jon posted a while back. I refer to it often.
    Thank you JonnyMac.

Sign In or Register to comment.