@LunaSole : I like your macros very much.
Very good idea, + excellent and simple implementation.
Bravo !
However, I'll use them by counting up from 0.
As Little John suggested, i think it's better to stick to some standards sometimes.
I'd also like to point out that, while you explain that
'Value' is bitmask, it is actually a
bitfield.
A
bitmask is a
pattern used to filter out or isolate specific bits in a bitfield.
Thank you for your very useful macros.
--------------------------------------------------
Addendum :
I think there is a mistake in your
BitOFF() macro.
You are using an XOR operation to turn the bit OFF,
which works if the bit is ON, but fails if it is already OFF !
Try this out.
Code: Select all
; using Lunasole's irregular 1-based position counting scheme
Macro BitOFF (Value, bit)
Value ! (1 << (bit-1)) ;; a zero bit will be turned on with this !
EndMacro
A = 15
Debug "A = " + Bin(A, #PB_Long)
A = BitOFF(A,1)
Debug " BitOFF(A,1) A = " + Bin(A, #PB_Long)
Debug ""
Debug "That bit #1 went from ON to OFF. OK."
Debug "Even though it's OFF, let's turn it OFF once more :"
Debug ""
A = BitOFF(A,1)
Debug " BitOFF(A,1) A = " + Bin(A, #PB_Long)
Debug ""
Debug "That bit #1 went from OFF to ON."
Debug "Not the expected result..."
Debug ""
Now,
INVERTING the bit and then
ANDing it against the bitfield works perfectly :
Code: Select all
; using Lunasole's irregular 1-based position counting scheme
Macro BitOFF (Value, bit)
Value & ~(1 << (bit-1))
EndMacro
A = 15
Debug "A = " + Bin(A, #PB_Long)
A = BitOFF(A,1)
Debug " BitOFF(A,1) A = " + Bin(A, #PB_Long)
Debug ""
Debug "That bit #1 went from ON to OFF. OK."
Debug "So it's OFF, but let's turn it OFF again anyway :"
Debug ""
A = BitOFF(A,1)
Debug " BitOFF(A,1) A = " + Bin(A, #PB_Long)
Debug ""
Debug "And bit #1 stayed OFF, as we wanted..."
Debug ""