Basic Stamp 2P with dealing with Binary Code
Duke
Posts: 21
Hi,
I'm working with a simple circuit of reading 4 rapid switches·on port 4 5 6 7 (Port INB)
The·pattern·of switch·read·can be·16 possible binary patterns
The program is like this
'
PortData·VAR Nib······················ 'Declare var type
MAIN:
· OUTB =~INB
··PortData = OUTB·····················'Set value "PortRead" equal to Pin 4-7
· DEBUG IBIN·PortData ,CR·········· 'Display Binary Value of Pin 4-7
GOTO MAIN
'
Result on DEBUG Screen shows
%0001
%0001
%0011
%0011
%0110
%0110
%1110
%1000
%1000
%0000
.. As it continues
I want to extract only 2 Higher bit or 2 Lower bits Like..
Low··························· High······················X = ignore
%00XX··-->00············· %XX01· -->01
%00XX··-->00··············%XX01· -->01
%00XX··-->00··············%XX11· -->11
%00XX··-->00············· %XX11· -->11
%01XX··-->01··············%XX10· -->10
%01XX··-->01············· %XX10· -->10
%11XX··-->11············· %XX10· -->10
%10XX··-->10············· %XX00· -->00
%10XX··-->10············· %XX00· -->00
%00XX··-->00············· %XX00· -->00
Are there·some math function or some short programs that can do this extraction.
Aslo it would be useful if you can advise me how·to read only 2 bits data at one time
I will use it instead of "INB" Command.
Thank you.
Duke..
I'm working with a simple circuit of reading 4 rapid switches·on port 4 5 6 7 (Port INB)
The·pattern·of switch·read·can be·16 possible binary patterns
The program is like this
'
PortData·VAR Nib······················ 'Declare var type
MAIN:
· OUTB =~INB
··PortData = OUTB·····················'Set value "PortRead" equal to Pin 4-7
· DEBUG IBIN·PortData ,CR·········· 'Display Binary Value of Pin 4-7
GOTO MAIN
'
Result on DEBUG Screen shows
%0001
%0001
%0011
%0011
%0110
%0110
%1110
%1000
%1000
%0000
.. As it continues
I want to extract only 2 Higher bit or 2 Lower bits Like..
Low··························· High······················X = ignore
%00XX··-->00············· %XX01· -->01
%00XX··-->00··············%XX01· -->01
%00XX··-->00··············%XX11· -->11
%00XX··-->00············· %XX11· -->11
%01XX··-->01··············%XX10· -->10
%01XX··-->01············· %XX10· -->10
%11XX··-->11············· %XX10· -->10
%10XX··-->10············· %XX00· -->00
%10XX··-->10············· %XX00· -->00
%00XX··-->00············· %XX00· -->00
Are there·some math function or some short programs that can do this extraction.
Aslo it would be useful if you can advise me how·to read only 2 bits data at one time
I will use it instead of "INB" Command.
Thank you.
Duke..
Comments
· twoBits = theNib >> 2
To simply keep the lower two bits:
· twobits = theNib & %0011
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
That is exactly what I want!, My program is working now.
Duke..