Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC bit manipulation!! — Parallax Forums

PBASIC bit manipulation!!

thegrimthegrim Posts: 5
edited 2006-01-18 04:35 in BASIC Stamp
can somebody tell me qhere can i find a good resource to learn how to manipulate bits with the pbasic language.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 03:45
    If you're talking about the BS2 family, PBASIC is quite flexible -- any bit of any variable can be directly manupulated.· In other languages, for example, to force Bit7 to "1" you might have to do something like this:

    · myVal = myVal | 128··· ' force bit 7 high

    ... whereas in PBASIC 2.x you can do this:

    · myVal.BIT7 = 1

    Your question is very wide open.· What kinds of things are you looking to do?· If it's just curiosity, read through section four of the manual and scan our books and code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • thegrimthegrim Posts: 5
    edited 2006-01-17 04:34
    thank for the explanation!!
    i wasnt clear at all, i want to learn how to manipulate bits in the way of make shifts(left and right) , rotate and all those things that can be done in other high level languages but like an introductoin in pbasic language.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 06:02
    There are operators for shifting, but to rotate a value you'll need a carry bit and some code·-- something like this:

    myValue··· VAR·· Byte
    carry······VAR·· Bit

    Main:
    · myValue = %11000000
    · ' rotate left
    · carry = myValue.BIT7
    · myValue = myValue << 1
    ··myValue.BIT0 = carry
    · ' display -- should be %10000001
    · DEBUG BIN8 myValue

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-01-17 20:35
    Jon:
    Now, I must tell you I worked and worked, looked and looked, for nearly 2 hours... and finally, trimphuantly discovered.... the exact same code as you just casually posted... LOL... I had to work for it, so now I guess I'll remember it better, eh?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Until our bytes cross again, may your chips never smoke, your bits never fall off, your parts bin never be empty and your jumpers never fall off.
    KK
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-17 21:58
    Don't feel bad... I've been "working" BASIC Stamps for over 12 years, and learned a lot of lessons along the way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • thegrimthegrim Posts: 5
    edited 2006-01-18 04:29
    where can i find text about it??
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-18 04:35
    Go to our web site and you'll find a whole bunch downloadable books -- the best place to start, of course, is the manual.

    Here are a few links to get you going:

    http://www.parallax.com/dl/docs/prod/stamps/web-BSM-v2.2.pdf
    http://www.parallax.com/html_pages/edu/curriculum/sic_curriculum.asp
    http://www.parallax.com/dl/docs/books/sw/Web-sw-v2.0.pdf

    Have fun!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.