But maybe someone find following variations usable/useful/interesting, time ago I composed them to make some "standart for bit moving stuff" (also to stop messing with bit constants and keep code clean from ugly bit operators).
NOTE: BitSet and BitOff here are specially designed to be usable in both forms, with asigment and without it: "A = BitSet (A, 1)" and "BitSet (A, 1)". Such an "amazing universality and portability" caused some restrictions (see comments).
Also, it is recommended to add all 3 keywords to custom keywords and set highlight color for them the same as used for PB keywords

Code: Select all
; check if value has specified bit set up
; RETURN: 1 or 0
Macro BitGet (Bitfield, Bit)
Bool(Bitfield & (1 << Bit)) ; or: ((Bitfield & (1 << Bit)) >> Bit) ; or: ~~(Bitfield & (1 << Bit)) ; (both won't work nice)
EndMacro
; BitSet macro IS NOT SAFE to use in expressions where it is surrounded by "~,<<,>>,%,!" operators.
; BitOff macro too, but another set of operators: "~,<<,>>,%"
; You can add brackets to macro code to avoid such restrictions, but that will also disallow use w/o assignment.
; set up specified bit
; RETURN: modified bitfield, or result stored inside "Bitfield" if no assignment operator
Macro BitSet (Bitfield, Bit)
Bitfield | (1 << Bit)
EndMacro
; removes specified bit
; &-fix by Blue (I think he made it in deep meditation)
; RETURN: modified bitfield, or result stored inside "Bitfield" if no assignment operator
Macro BitOff (Bitfield, Bit)
Bitfield & ~(1 << Bit)
EndMacro