Why is their no Bitwise AND NOT in BS2
I'm trying to determin a bit changing in a byte of data recived from an IC2 chip.
I'm writing a debug rotine to test it.
the &/ only works with a BS1?
how would I do this in a BS2?
This seams to work, but don't seam optimal.
Post Edited (RickH) : 5/21/2008 9:34:50 AM GMT
I'm writing a debug rotine to test it.
DebugCode: RANDOM DebugVar1 DebugVar2 = %10101010 DebugVar3 = Debugvar1 | DebugVar2 DebugVar4 = DebugVar1 & DebugVar2 DEBUG "Var1: ",BIN8 DebugVar1," Var1: ",BIN8 DebugVar1," ",CR DEBUG "Var1: ",BIN8 DebugVar2," Var1: ",BIN8 DebugVar2," ",CR DEBUG "OR: ",BIN8 DebugVar3," AND : ",BIN8 DebugVar4," ",CR FOR idx = 7 TO 0 storage1 = debugvar1 << idx storage1 = storage1 >> 7 storage2 = debugvar2 << idx storage2 = storage2 >> 7 changed = storage1 ^ storage2 bitWentHigh = storage1 [color=red]&/[/color] storage2 DEBUG BIN storage1," ",BIN storage2," ",BIN ? changed," ",BIN ? bitwenthigh,CR NEXT PAUSE 16384 DEBUG CLS RETURN
the &/ only works with a BS1?
how would I do this in a BS2?
This seams to work, but don't seam optimal.
' {$STAMP BS2p}
' {$PBASIC 2.5}
DebugVar1 VAR Byte
DebugVar2 VAR Byte
storage1 VAR Byte
storage2 VAR Byte
results VAR Byte
Bit_Changed VAR Bit
BitWentHigh VAR Bit
idx VAR Nib
Bitreg VAR Nib
setup:
DebugVar1 = %10101010
main:
GOSUB DebugCode
GOTO main
DebugCode:
Bitreg = 0
RANDOM DebugVar1
DebugVar2 = %10101010
DEBUG "Var1: ",BIN8 DebugVar1," Var1: ",BIN8 DebugVar1," Var1: ",BIN8 DebugVar1," ",CR
DEBUG "Var2: ",BIN8 DebugVar2," Var2: ",BIN8 DebugVar2," Var2: ",BIN8 DebugVar2," ",CR
DEBUG " OR: ",BIN8 (Debugvar1 | DebugVar2)," AND: ",BIN8 (DebugVar1 & DebugVar2)," XOR: ",BIN8 (DebugVar1 ^ DebugVar2)," ",CR
FOR idx = 7 TO 0
storage1 = debugvar1 << idx
storage1 = storage1 >> 7
storage2 = debugvar2 << idx
storage2 = storage2 >> 7
bit_Changed = storage1 ^ storage2
IF bit_changed = 1 THEN
IF storage1 > storage2 THEN
BitwentHigh = 1
ELSE
BitWenthigh = 0
ENDIF
ELSE
BitWentHigh = 0
ENDIF
DEBUG BIN storage1," - ",BIN storage2," - Bit ",DEC Bitreg," Changed: ",BIN bit_changed," - Bit ",DEC Bitreg, " Went HIGH: ",BIN bitwenthigh,CR
IF Bit_Changed = 0 AND BitWentHigh = 1 THEN
DEBUG "ERROR"
ENDIF
Bitreg = Bitreg+1
NEXT
PAUSE 32768
DEBUG HOME
RETURN
Post Edited (RickH) : 5/21/2008 9:34:50 AM GMT

Comments
&/ Bitwise AND NOT
|/ Bitwise OR NOT
^/ Bitwise XOR NOT
I was just wondering why.
z = x &~ y ' bitwise AND NOT
z = x |~ y ' bitwise OR NOT
z = x ^~ y ' bitwise XOR NOT
For detecting a change from low to high in the bits of a variable I usually use the following function:
changedHigh = newvalue ^ oldvalue & newvalue
The only 1's in changedHigh will be bits that were 0 in oldvalue and have become 1 in newvalue. That can process 16 bits at once in parallel or a byte or nib or single bit. Say it is a byte, then
IF changedHigh.bit0(5) THEN GOSUB action
will take the action if bit 5 has changed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com