How to address bits in a Byte
bsnut
Posts: 521
Is it possible to address bits in a byte or longs in Spin?
I know how to do it with Basic Stamps and also understand may have to use the binary numbers to do what I want in Spin. Is this what, I have to do?
I know how to do it with Basic Stamps and also understand may have to use the binary numbers to do what I want in Spin. Is this what, I have to do?
Comments
(Using short numbers for demonstration...)
0010 left shift would be 0100
0010 right shift would be 0001
Then you can pick out specific bits using AND with a "mask"...
1011 AND with mask 0001 would be 0001
1010 AND with mask 0001 would be 0000
1011 AND with mask 0010 would be 0010
1001 AND with mask 0010 would be 0000
1011 AND with mask 1111 would be 1011
The "mask" is whatever you want to make it. The 1's in the mask being the bits you want to pick out.
Note that when porting BASIC Stamp code to the Propeller you won't always want to use these methods, you may end up with inline code as it's more efficient (e.g., duplicating SHIFTIN or SHIFTOUT).
Is there way I can get copy of the templale you use
It's attached. I prefix it with underscores to force it to the top of the files pane in the Propeller Tool -- makes it easy to find.