Shop OBEX P1 Docs P2 Docs Learn Events
schiftl of shiftr — Parallax Forums

schiftl of shiftr

stefstef Posts: 173
edited 2007-01-30 22:32 in General Discussion
Hi

I'm working on a little project that is reading pulses on an input an generating pulses after modification on an output.

I'm using shift to read from a pin into an byte.
I'm using also shift to shift a byte back out to an other pin.

Now my· question. Is thier a way to schift from on byte to an other byte. (not to a hardware output)

example.·myvar = 10001100 ( this can be any number depending on what I read)
I want to create 8 byte var where the first is bit 1 of myvar (0) and the last is bit 8 of myvar (1)
(var1=0, var2=0, var3=1, var4=1, var5=0, var6=0, var7=0,var8=1)
This I need in a routine that when I read myvar i can automatic change var1 until var8 depending on the value in myvar.

Is this possible in a sx28 using sx/b???

stef

Comments

  • BeanBean Posts: 8,129
    edited 2007-01-30 12:08
    Something like this should do:

    FOR cnt = 0 TO 7
      result(cnt) = myVar.0
      myVar = myVar >> 1
    NEXT
     
    

    Note that this will destory the value in myVar...

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman

    Post Edited (Bean (Hitt Consulting)) : 1/30/2007 1:37:13 PM GMT
  • stefstef Posts: 173
    edited 2007-01-30 13:45
    Hi bean

    Thanks for the response. I understand the routine. I oversaw the >> 1 command.

    Just one litle question : In "result(cnt) = myvar.0" What is the reason of the ".0"? Can it also work with just "result(cnt) = myvar"

    It is just to understand the reason. I like to understand what I do.



    Stef
  • BeanBean Posts: 8,129
    edited 2007-01-30 13:52
    Stef,
    The ".0" means you only want the value of bit 0. A zero or a one.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • stefstef Posts: 173
    edited 2007-01-30 21:41
    Thanks bean

    I seached all my doc and found nothing on it.
    Deamed you are good. I still need a lot to learn. Where can I find more on this??

    Thanks anyway. I implemented the routine in my program (with a bit of modification on it but I don't think you mind.)

    stef
  • JonnyMacJonnyMac Posts: 9,284
    edited 2007-01-30 22:32
    I'm writing a book on SX/B programming so I'll be sure to include a note in that regard. And yes, Bean is the best at SX/B -- he created the compiler! (and had the infinite patience to put up with my suggestions along the way).
Sign In or Register to comment.