Accessing Individual bits within a byte
Branmuffin Industries
Posts: 35
I am trying to overwrite the four low bits in a byte while leaving the four high bits alone. it used to be, with the basic stamp, we could individually address the bits of a byte with the .bit[noparse][[/noparse]0] command. Since we can no longer do that, does anyone have an idea for a workaround?
Ryan Brandys
Ryan Brandys
Comments
In Spin or ASM just some quick pointers..explore further from there
Spin
old : = old & new
ASM 'setting bits to zero
and old, new 'new..zero for overwriting to zero just alter the 4 lsb bits..
ASM 'setting bits to one
or old,new
Rgds Ron Mel oz
this replaces the lower 4 bits in a with the lower 4 bits in b.
I see Ron beat me to it, I agree with his advice.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
PUB Scanning( _Pack ) | counter, pos, addme , eraser
pos := 1
repeat counter from 0 to 16
if _Pack == LeftPack
eraser := %1010_1010_1111_1111
if pos == 1
pos := 2
addme := %0000_0001_0000_0000
elseif pos == 2
pos := 3
addme := %0000_0100_0000_0000
elseif pos == 3
pos := 4
addme := %0001_0000_0000_0000
elseif pos == 4
pos := 1
addme := %0100_0000_0000_0000
else
eraser := %1111_1111_1010_1010
if pos == 1
pos := 2
addme := %0000_0000_0000_0001
elseif pos == 2
pos := 3
addme := %0000_0000_0000_0100
elseif pos == 3
pos := 4
addme := %0000_0000_0001_0000
elseif pos == 4
pos := 1
addme := %0000_0000_0100_0000
BattState := BattState & eraser
BattState := BattState | addme
WriteLEDS 'update LED array
waitcnt( 9_000_000 + cnt)
If I understand the code that you posted corectly, you might be able to simplify it down to this...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.