PDA

View Full Version : PBASIC bit manipulation!!



thegrim
01-17-2006, 11:27 AM
can somebody tell me qhere can i find a good resource to learn how to manipulate bits with the pbasic language.

Jon Williams
01-17-2006, 11:45 AM
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

thegrim
01-17-2006, 12:34 PM
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 Williams
01-17-2006, 02:02 PM
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 Kidd
01-18-2006, 04:35 AM
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 Williams
01-18-2006, 05:58 AM
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

thegrim
01-18-2006, 12:29 PM
where can i find text about it??

Jon Williams
01-18-2006, 12:35 PM
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