Shop OBEX P1 Docs P2 Docs Learn Events
Reading Data from a string and comparing. — Parallax Forums

Reading Data from a string and comparing.

Paul K.Paul K. Posts: 150
edited 2009-10-19 17:09 in Propeller 1
Im having a hard time starting this on my own.· I am using the wireless playstation remote object and I have that working and
displaying that data thru my rca connection.

It's displaying the data in hex so I get something like this $FFFF5A73 this changes as I hit a button on the remote.
I have mapped out all the changes possible.

I am lost on how to read a change.·

EX: I hit the triangle button and I·get this in return $EFFF5A73 but am lost how to read the first bit in the sequence.
I know I can compare the whole string but thats alot of wasted time if each bit has 16 different options im looking at a table of like
a couple thousand different options.· If not more.· Is there a way to read each bit.

Thanks
Paul

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-10-19 04:49
    Paul K.,

    If the lower bits are insignificant in your comparison you can do something like this...

       If hex_data>>24 & $FF == $EF
          {triangle button pressed}
    
    


    third_num
    or even...

    {triangle button pressed}{triangle button pressed}
       If hex_data>>28 & $F == $E
          {triangle button pressed}
    
    





    If you want to look at a different position, say the 3rd one from the right where the 'A' is ... $FFFF5A73

    you could do something like this...


      eigth_num := hex_data>>28 & $F
      third_num := hex_data>>8 & $F
    
      if third_num == $A 
         {do something here}   
       
      if eigth_num == $E 
         {triangle button pressed}
    
    




    since Each HEX value represents 4 bits, the number to shift is the position from the right minus 1 times 4.

    so for the 8th position... (8-1)*4 = 28
    ...the 3rd position... (3-1)*4 = 8


    If the number that you want to look at is a BYTE (8-bits) ... same thing, but instead of multiplying by 4, multiply by 8.

    in the first example... 'If hex_data>>24 & $FF == $EF'

    ...this was the 4th BYTE from the right... so (4-1)*8 = 24

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/19/2009 5:12:02 AM GMT
  • Paul K.Paul K. Posts: 150
    edited 2009-10-19 17:09
    Pretty straight foward. Alot simpler than I thought.

    Thanks
    Paul
Sign In or Register to comment.