Convert binary pins to decimal?
Oldbitcollector (Jeff)
Posts: 8,091
I'm creating a routine that look like this..
(I know the pins are goofy, but everything else is allocated.)
var =: ina[noparse][[/noparse]31,30,16,9,4,5,6,7]
I want to bring var in as a binary number, then convert it to a decimal variable.
Can someone show me how to do this?
My binary truth table for this is:
31=128
30=64
15=32
9=16
4=8
5=4
6=2
7=1
Thanks
Oldbit
(I know the pins are goofy, but everything else is allocated.)
var =: ina[noparse][[/noparse]31,30,16,9,4,5,6,7]
I want to bring var in as a binary number, then convert it to a decimal variable.
Can someone show me how to do this?
My binary truth table for this is:
31=128
30=64
15=32
9=16
4=8
5=4
6=2
7=1
Thanks
Oldbit
Comments
'Arrange ina bits into x
x~
repeat i from 1 to 8
x := x<<1 + ina[noparse][[/noparse]lookup(i : 31, 30, 15, 9, 4, 5, 6, 7)]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
var := ((var >> 24) & $C0) | ((var >> 10) & $20) | ((var >> 5) & $10) | ((var >> 4) >< 4)
var := ina[noparse][[/noparse] 31] << 7 + ina[noparse][[/noparse] 30] << 6 + ina[noparse][[/noparse] 16] << 5 + ina[noparse][[/noparse] 9] << 4 + ina[noparse][[/noparse] 4] << 3 + ina[noparse][[/noparse] 5] << 2 + ina[noparse][[/noparse] 6] << 1 + ina[noparse][[/noparse] 7]
Even close anyone?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
BTW, Chip, see anything familiar in this pic? [noparse]:)[/noparse] [noparse]:)[/noparse]
Oldbit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
After 1 day my brain would be shot!
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·